OK, so I have done some more troubleshooting and narrowed the problem down
and eliminated the switch factor. I am thinking that this may be a bug in
the New Serial Manager, but I don't have enough experience to make that
determination yet. I would be interested if others can reproduce the same
problem. Here is my problematic code:
// set the baud rate to 9600
rate = 9600;
err = SrmControl(portID, srmCtlSetBaudRate, &rate, &ratesize);
// copy my string into the send buffer and send it
StrCopy(sendBuffer, "This is a test.");
dataSent = SrmSend(portID, &sendBuffer, 15, &err);
//flush the FIFO
SrmSendWait(portID);
// change the baud rate to 4800
rate = 4800;
err = SrmControl(portID, srmCtlSetBaudRate, &rate, &ratesize);
When I do this, 95% of the time the end of my string is truncated. If I
introduce a delay after the SrmSendWait then the code works fine. I suspect
that the SrmSendWait function isn't doing what it is supposed to...or else I
am misunderstanding what it is supposed to do. Can anybody shed some light
on this?
Steve
> -----Original Message-----
> Hi all,
>
> I am trying to control a B&B Electronics 232MSS2 serial
> switch from the
> serial port of my Symbol 1700. I am using a switch since I need to
> communicate with an ARDIS modem, a GPS unit and a printer. I
> am using the
> New Serial Manager with SDK 3.5 and CodeWarrior on Windows NT.
>
> To operate the switch, I use
>
> err = SrmControl(portID, srmCtlSetBaudRate, &baudRate, &ratesize);
>
> to set the communications buad rate to that of the switch.
> Then I send a
> command to the switch to change the active port and finally I
> issue another
> SrmControl command to change the communications baud rate to
> that of the
> device that is connected to that port on the switch.
>
> To get everything to work properly, I had to introduce a
> delay between the
> time I send the "change switch port" command to the switch
> and when I change
> the buad rate. I can't figure out why I need this delay. I
> am already
> using a
>
> SrmSendWait(portID);
>
> to allow all data to clear from the transmit FIFO.
>
> Here is a chunk of my code
>
>
> static Err SwitchPort(UInt16 portID, UInt8 portNum, Int32
> baudRate, Int32
> controlRate)
> { Err err = 0;
> UInt16 ratesize = sizeof(Int32);
> UInt32 dataSent;
> char sendBuffer[100];
> UInt16 i;
>
> //set the baud rate to the control rate that the switch wants
> err = SrmControl(portID, srmCtlSetBaudRate,
> &controlRate, &ratesize);
>
> //set command sequence to close active port and open new port
> sendBuffer[0] = 27;
> sendBuffer[1] = 2;
> sendBuffer[2] = 4;
> sendBuffer[3] = 27;
> sendBuffer[4] = 2;
> sendBuffer[5] = portNum;
> dataSent = SrmSend(portID, sendBuffer, 6, &err);
>
> //flush the FIFO
> err = SrmSendWait(portID);
>
> //introduce short delay. This codes does not work if
> this is removed
> for (i=0; i<300; i++)
> ;
>
> //change the baud rate to the target device
> err = SrmControl(portID, srmCtlSetBaudRate, &baudRate,
> &ratesize);
>
> return err;
> }
>
> Anyone know what I am doing wrong or is it normal to need
> this artificial
> delay? If it turns out that I need a delay, what is the most
> appropriate
> way to accomplish it? Is there a better approach to
> communicating with
> multiple serial devices?
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/