# include "stdafx. H"
# include & lt; Iostream>
# include "string"
# include & lt; Fstream>
H # include "Windows."
# include "Winbase. H"
# include "SerialPort. H"
using namespace std;
# define RECFRAMELEN 3
# define uchar unsigned char
# define SENDFRAMELEN 10
Uchar receiveData [RECFRAMELEN - 1);
Uchar sendBuff [SENDFRAMELEN]={' 1 ',};
Uchar AnalysisData (uchar * data)
{
The return data [0];
}
Int main ()
{
CSerialPort RS485.
For (;; )//cycle waiting for connecting a serial port
{
If (RS485. InitPort (3, 9600))
break;
The else
Sleep (50);
}
RS485. WriteData (sendBuff SENDFRAMELEN);
Cout & lt;
if (true !=RS485. OpenListenThread ())
{
Cout & lt; <"The Open rs485 failed or serial port has already the opened! Both Please check your setting!"
}
While (1)
{
If (RS485. DataReady==TRUE)
{
RS485. DataReady=FALSE;
//AnalysisData (receiveData);
Cout & lt;
}
};
Under the great god, please help to see, thank you very much!!!!!
CodePudding user response:
Why not open the receiving thread first, finish your hair again open, one thousand time,CodePudding user response:
Thread has opened before receiving data.CodePudding user response:
Don't sink ah, it's urgent for helpCodePudding user response:
PLC is what,,,CodePudding user response:
PLC without MODBUS protocol? Free the agreement?CodePudding user response:
Use serial energy such as serial port tool manually send first to see if normal?