Setting baud rate for PSC USB
I am writing an interface for the PSC USB in C# (.NET express 2005).
I have every thing working now except for setting the baud rate.
I am not getting a result when I do the· !SCSBR... call for 38K4.
Below the code:
public void SetBaudRate(byte Rate)
{
byte[noparse]/noparse Token = new byte[noparse][[/noparse]8];
byte[noparse]/noparse PSCBuffer = new byte[noparse][[/noparse]11];
// The buffer may not be empty, so this is done explicitly
Com.DiscardInBuffer();
// 01234567
Token = Ascii.GetBytes("!SCSBR_\x0D");
// Syntax: !SCSBR x $0D (no spaces)
// Where x = 0 for 2400 or 1 for 38K4
// Reply: BR x (no spaces / 3 bytes)
Token[noparse][[/noparse]6] = Rate;
Com.Write(Token, 0, Token.Length);
// Com.Read(PSCBuffer, 0, 8);
switch (Rate)
{
·· case Baud2400:
····· Com.BaudRate = 2400;
····· break;
·· case Baud38K4:
····· Com.BaudRate = 38400;
····· break;
·· default:
····· ErrorMessage("SetBaudRate - Wrong baud rate.");
····· break;
}
// wait for 4 seconds to give the PSC the chance to respond
Pause(4);
// returns the command (8 positions) and the baud rate (3 positions)
Com.Read(PSCBuffer, 0, 11);
// Com.Read(PSCBuffer, 0, 3);
}
Note that also the·version with the
Com.Read(PSCBuffer, 0, 8);
Statement works, but then there is a time out for
Com.Read(PSCBuffer, 0, 3);
because there is no output from the PSC.
Any hints ???
Herman.
I have every thing working now except for setting the baud rate.
I am not getting a result when I do the· !SCSBR... call for 38K4.
Below the code:
public void SetBaudRate(byte Rate)
{
byte[noparse]/noparse Token = new byte[noparse][[/noparse]8];
byte[noparse]/noparse PSCBuffer = new byte[noparse][[/noparse]11];
// The buffer may not be empty, so this is done explicitly
Com.DiscardInBuffer();
// 01234567
Token = Ascii.GetBytes("!SCSBR_\x0D");
// Syntax: !SCSBR x $0D (no spaces)
// Where x = 0 for 2400 or 1 for 38K4
// Reply: BR x (no spaces / 3 bytes)
Token[noparse][[/noparse]6] = Rate;
Com.Write(Token, 0, Token.Length);
// Com.Read(PSCBuffer, 0, 8);
switch (Rate)
{
·· case Baud2400:
····· Com.BaudRate = 2400;
····· break;
·· case Baud38K4:
····· Com.BaudRate = 38400;
····· break;
·· default:
····· ErrorMessage("SetBaudRate - Wrong baud rate.");
····· break;
}
// wait for 4 seconds to give the PSC the chance to respond
Pause(4);
// returns the command (8 positions) and the baud rate (3 positions)
Com.Read(PSCBuffer, 0, 11);
// Com.Read(PSCBuffer, 0, 3);
}
Note that also the·version with the
Com.Read(PSCBuffer, 0, 8);
Statement works, but then there is a time out for
Com.Read(PSCBuffer, 0, 3);
because there is no output from the PSC.
Any hints ???
Herman.
Comments
Token = Ascii.GetBytes("!SCSBR_\r");
regards peter
I think I have a partial solution.
I do in C# an additional open and close of the COM port.
Why that is needed I do not totally understand ...
The result is a working 38K4 connection.
However the 3 bytes output are not produced ...
Is this due to the USB driver ??
public void SetBaudRate(byte Rate)
{
byte[noparse]/noparse Token = new byte[noparse][[/noparse]8];
byte[noparse]/noparse PSCBuffer = new byte[noparse][[/noparse]11];
// The buffer may not be empty, so this is done explicitly
Com.DiscardInBuffer();
// 01234567
Token = Ascii.GetBytes("!SCSBR_\x0D");
// Syntax: !SCSBR x $0D (no spaces)
// Where x = 0 for 2400 or 1 for 38K4
// Reply: BR x (no spaces / 3 bytes)
Token[noparse][[/noparse]6] = Rate;
Com.Write(Token, 0, Token.Length);
Com.Read(PSCBuffer, 0, 8);
Com.Close();
switch (Rate)
{
case Baud2400:
Com.BaudRate = 2400;
break;
case Baud38K4:
Com.BaudRate = 38400;
break;
default:
ErrorMessage("SetBaudRate - Wrong baud rate.");
break;
}
// wait for 2 seconds to give the PSC the chance to respond
Pause(2);
Com.Open();
}
Herman.
I'm just guessing here, though.
Kwok
This is the SetBaud method.
Once you set the PSC baud rate you need change the serial connection to the new baud. I took the lazy path and closed the connection then opened it again and lose the PSC response. You could use the DCB structure in windows but that's a bit of work. I don't think the serialport object in VS2005 allows you to change the serial port baud on the fly. After you change the baud then send the ?Ver command to verify your connection.
Post Edited (Mike Gebhard) : 10/27/2006 2:22:37 AM GMT
Mike