I'm trying to understand the use of a int variable used for a serial port number. (from RE232.H 2016, Example code has No "-1" used here ->
http://cc.bingj.com/cache.aspx?q=%22RS232_SendBuf%22&d=4562511026390469&mkt=en-US&setlang=en-US&w=vTNhPMMo3EwaynsXkoqfxcLypDxFVl16
My variable (port_nr=0) has values like: 0, 1, 2, etc.
Im my test code, I can open the com port using the below code, without the "-1" after the 'port_nr'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void SerialDemFrame::OnconBut2Click(wxCommandEvent& event)
{
int baudrate=9600;
port_nr=0; // 0 = Com1, 1 = Com2, etc.
char mode[] = {'8','N','1',0};
wxString comSelected = comSel->GetStringSelection();
int port_aux = 0;
if(comSelected.size() > 1)
{
port_aux = (int) comSelected[3] - 48;
if(port_nr == 0)
{
//Syntax: RS232_OpenComport(com port number, baudrate, mode)
if(!RS232_OpenComport(port_nr, baudrate, mode))
{
port_nr = port_aux;
recBox->SetValue((char)(port_aux+48));
}
}
}
}
|
But in Sending a string via serial port using the example syntax,
void RS232_cputs(int comport_number, const char *text)
my 'port_nr' variable Must be followed by a "-1".
I am trying to learn why the "-1" is necessary in this particular location and no where else.
When I remove the "-1" the serial message does not send.
When I add 'int' to my declaration like this: int port_nr=0, with and without "-1", the message does not send.
This is my full Sending code:
1 2 3 4 5 6 7 8 9 10
|
void SerialDemFrame::OnsendBut2Click(wxCommandEvent& event)
{
wxString sendMesg = mesBox->GetValue();
string sended;
sended = sendMesg.ToStdString();
if(port_nr > 0)
RS232_cputs(port_nr-1, (char*)sended.c_str());
}
|
Why can't I just Type the 'port_nr' as int, and use it throughout, without the "-1"?