Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
西门子PLC与Arduino之间的串行通信_Arduino_Serial Port_Serial Communication_Plc_S7 1200 - Fatal编程技术网

西门子PLC与Arduino之间的串行通信

西门子PLC与Arduino之间的串行通信,arduino,serial-port,serial-communication,plc,s7-1200,Arduino,Serial Port,Serial Communication,Plc,S7 1200,我想使用西门子S7-1200与CM 1241(RS-232)进行串行通信,并与我的Arduino进行通信。 以下是通信的设置。我有两个温度传感器和一个Led连接到我的Arduino,在PLC侧,我有西门子的S7-1200和CM-1241。Arduino和我的PLC仅通过Tx和Rx引脚连接,不进行握手 我正在将温度数据从两个传感器发送到PLC。在PLC侧,我根据不同的温度值决定何时打开连接到arduino的Led。在发送数据之前,我已经为两个传感器分配了一个ID。这就是从Arduino传输的数据看

我想使用西门子S7-1200与CM 1241(RS-232)进行串行通信,并与我的Arduino进行通信。 以下是通信的设置。我有两个温度传感器和一个Led连接到我的Arduino,在PLC侧,我有西门子的S7-1200和CM-1241。Arduino和我的PLC仅通过Tx和Rx引脚连接,不进行握手

我正在将温度数据从两个传感器发送到PLC。在PLC侧,我根据不同的温度值决定何时打开连接到arduino的Led。在发送数据之前,我已经为两个传感器分配了一个ID。这就是从Arduino传输的数据看起来像$AOPT_TEMP1_20_TEMP2_21的方式

到目前为止,我使用RCV_PTP(接收到的数据放在缓冲区上)在我的PLC上接收串行数据,并使用SEND_PTP发送数据。我还在PLC上实现了一个过滤器,它将只接受以“$AOPT_”开头的串行数据。现在,我想从两个温度传感器TEMP1和TEMP2接收温度值,然后控制Led。例如,如果(TEMP1>TEMP2),则打开Led,否则关闭

我能够从Arduino接收PLC上的数据,但现在我不知道如何继续比较接收到的信息。如何从接收到的缓冲区提取唯一需要的数据?如有任何建议,将不胜感激


提前感谢….

在SCL中解析字符串(从串行缓冲区)很简单: 您可以使用以下命令: **

** 在此SCL备忘单上找到:

我想从

  • 在SCL中创建功能块
  • 添加一个输入属性作为 串
  • 将两个输出属性(Temp1、Temp2)添加为real或int
  • 用于临时字符串和文本->实转换的多个静态变量
类似于以下内容分析您的代码(因为我没有TIA门户,这可能需要修改): 为您的字符串“$AOPT_TEMP1_20_TEMP2_21” 假设开头总是“$AOPT_TEMP1_”(12个字符)

请记住,这些都是我想不起的,使用手册可以快速参考:


有些事情可能需要调整。如果您不/不能使用SCL,这些块也存在于梯形图中。如果可以,您可以将此功能块连接起来,仅在收到缓冲区后执行

,以确认您正在询问PLC端的文本处理?是的,在PLC端
LEN
CONCAT
LEFT or RIGHT
MID
INSERT
DELETE
REPLACE
FIND
EQ_STRNG and NE_STRNG
GE_STRNG and LE_STRNG
GT_STRNG and LT_STRNG
INT_TO_STRING and
STRING_TO_INT
DINT_TO_STRING and
STRING_TO_DINT
REAL_TO_STRING and
STRING_TO_REAL
temp1_temp:=DELETE(IN1:=inputmsg,IN2:='$AOPT_TEMP1_',L:=12,P:=0);

//result should be "20_TEMP2_21"
//if you have a result above or below a 2 digit number we can't just get 
//the next two chars in the string.  so we use the FIND.

temp1_endpos:=FIND(IN1:=temp1_temp,IN2:='_');
temp1_str:=LEFT(IN1:temp1_temp,L:=temp1_endpos);
Temp1:=string_to_real(temp1_str); 

//work off of the position of the temp1_endpos and the string stored in
//temp1_temp

temp2_str:=RIGHT(IN1:=temp1_temp,LEN(temp1_temp)-temp1_endpos-6);

//working from the right side of the string 
// 20_TEMP2_21
//   ^-------pos 2   temp2_ is another 6 so we subract another 6
//         ^---pos 6
// len was (in this case) 11, we work from the right because we don't 
    // know how many digits each temp may be.

Temp2:=string_to_real(temp2_str);