Home > Software engineering >  Novice, PC and with Siemens PLC using VC serialPort class, serial communication, receive less than P
Novice, PC and with Siemens PLC using VC serialPort class, serial communication, receive less than P

Time:10-15

The source code is as follows:
# 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; RS485. SetupPacketConfig (x5a receiveData, RECFRAMELEN xa5 0, 0).
if (true !=RS485. OpenListenThread ())
{
Cout & lt; <"The Open rs485 failed or serial port has already the opened! Both Please check your setting!" return -1;
}
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 help

CodePudding 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?