
Sensoray 2600 Programming Guide 69 Comport Transaction Functions
Example: // Send an ASCII string to COM1 on MM number 0. Note that the message size
// is reduced by 1 because we don’t want to transmit the null stored at the
// end of the string.
char Msg[] = "This is a test.";
u32 errstat = S26_ComSend( 0, 1, Msg, sizeof(Msg) - 1, 1000, 1 );
if ( errstat & GWERRMASK )
printf( "COM1 error detected.\n" );
else if ( errstat & COM_REJECTED )
printf( "insufficient COM1 buffer space.\n" );
else
printf( "Sent string to COM1.\n" );
Example: // Send a binary string to COM1 on MM number 0.
char Msg[] = { 1, 2, 3, 4, 5 };
u32 errstat = S26_ComSend( 0, 1, Msg, sizeof(Msg), 1000, 1 );
if ( errstat & GWERRMASK )
printf( "COM1 error detected.\n" );
else if ( errstat & COM_REJECTED )
printf( "insufficient COM1 buffer space.\n" );
else
printf( "Sent string to COM1.\n" );
8.3.2 S26_ComReceive()
Function: Returns data bytes from a comport’s serial receiver queue.
Prototype: u32 S26_ComReceive(u32 hbd, u8 LogDev, char *MsgBuf, u16 *MsgLen, u32 msec,u32 retries);
Returns: Error/status value, as described in section 8.1.1.
Notes: This function transfers bytes from the comport’s serial receiver queue into MsgBuf[]. If no bytes are present in the
queue, the byte count value at *MsgLen will be set to zero, otherwise the number of bytes that were transferred into
MsgBuf[] will be indicated by *MsgLen.
The target comport must be open when this function is called. If the comport is closed, the command will be
rejected and the status byte’s COM_REJECTED flag will be set.
Example: // Fetch and display an ASCII string from COM1 on MM number 0.
char RcvBuf[256]; // Buffer that will receive the string.
u16 BufLen = sizeof(RcvBuf); // Max number of characters to receive.
u32 errstat = S26_ComReceive( 0, 1, RcvBuf, &BufLen, 1000, 1 );
if ( errstat & GWERRMASK )
printf( "COM1 error detected.\n" );
else
{
Parameter Type Description
hbd u32
MM handle.
LogDev u8
Logical device identifier for the target comport. Specify a value from 1 to 4 to
address comport 1 to 4, respectively.
MsgBuf char*
Address of a buffer that is to receive the data bytes from the target comport.
MsgLen u16*
Address of a 16-bit application buffer that contains a byte count. Before calling this
function, set the byte count to the maximum number of bytes that are to be
transferred from the comport into MsgBuf[]. The function will transfer this
number of bytes, or all of the unread bytes in the serial receiver queue, whichever is
less. When the function returns, the byte count will be set to the number of bytes
that were transferred into MsgBuf[].
msec u32
Maximum time, in milliseconds, to wait for the MM to respond.
retries u32
Maximum number of transaction retry attempts.
Comentarios a estos manuales