DCC Motor Commands
With this function in place, all that was needed to was to actually send the trains motor commands. Dr Pankratz used some code I wrote to open a comm port in C++ to write functions to send the trains DCC commands. We initially had some problems finding a place to define a handle for the comm. port. First, we the compiler did not want to allow us to use the HANDLE identifier because it was part of windows.h and it stated that we could not use the windows header file inside of a MFC project. Dr. Pankratz rewrote code typecasting the HANDLE to a unsigned long. While this cleared up the first error, we were still unable to find a place to define the long int handle. We could define it when we were going to issue a motor command in the train method SetSpeed, but then it was necessary to open and close the port each time the command was sent. This was slow and unnecessary. I wanted to open the comm. port inside the resource manager when I opened the other ports to read the photocell and turnout statuses. However, when I tried to define the handle for the comm. port here I the compiler gave me many redefinition errors. After some time, I decided to wrap Dr. Pankratz’s .dll functions and define a global handle inside of that file. This worked wonderfully, and I recommend that Dr. Pankratz change his functions to include a global handle so that the wrapper functions are no longer needed. Also we could not get the function command to work which makes the headlight and taillight operations incomplete inside of the train methods.