永宏RS232任意點寫入格式詢問

想請問各位前輩

最近我嘗試透過RS232來連結永宏plc
在之前還蠻順利的,能夠照著
http://tw.myblog.yahoo.com/liu-yunan/
來做測試,也能夠通訊
但最近在嘗試多個任意點狀態或資料寫入時
卻一直出錯
回覆數字是0149404
查了通訊格式錯誤內容是:不合法的命令格式
因為liu-yunan大的網站圖片無法看清楚程式內容
所以我PO上我的格式內容
想請各為前被解惑

![](upload://eGQSzxrZLsPdWgkC64uHxQ1ONBl.jpeg)



使用for loop會自動index array,你原本有10筆資料要傳,如果你指定9,就只會有9筆資料,所以9可以省略,後面的0~9的部份也是可以省略,再試看看

![](upload://xVV63Jfre2FnPea1U2s7hdY1iqQ.jpeg)

另外,你以這樣的寫法要花多少時間完成寫入動作?

http://it360.tw/forum/forum_posts.asp?TID=13422&FID=23

ancle40647.6245717593

<font =“apple-style-span”=“” size=“3”>感謝<span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “><span =“bold”=”” style=“font-family: verdana, arial, helvetica, sans-serif; color: rgb(0, 0, 0); text-decoration: none; “>ancle回覆:

<font =“apple-style-span”=”” size=“3”><span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>我昨天有在嘗試<span =“apple-style-span”=”” style=“line-height: 24px; “>liu-yunan的內容
<span =“apple-style-span”=”” style=“line-height: 24px; “><font =“apple-style-span”=”” size=“3”>經過仔細的看文章後
<span =“apple-style-span”=“” style=“line-height: 24px; “><font =“apple-style-span”=”” size=“3”>發現我錯的地方是在數字格式的表示
<span =“apple-style-span”=“” style=“line-height: 24px; “><font =“apple-style-span”=”” size=“3”>並不是I32,而是使用V32
<span =“apple-style-span”=“” style=“line-height: 24px; “><font =“apple-style-span”=”” size=“3”>也不是I16,而是使用V16
<font =“apple-style-span”=“” size=“3”><span =“apple-style-span”=“” style=“line-height: 24px;”>這兩個小地方蠻容易被我忽略的
<font =“apple-style-span”=“” size=“3”><span =“apple-style-span”=“” style=“line-height: 24px;”>呵呵
<font =“apple-style-span”=“” size=“3”><span =“apple-style-span”=“” style=“line-height: 24px;”>也謝謝<span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>ancle回覆,發現我又沒發現錯的地方
<font =“apple-style-span”=”” size=“3”><span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>
<font =“apple-style-span”=”” size=“3”><span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>寫入PLC部分我並沒有計算傳送的時間
<font =“apple-style-span”=”” size=“3”><span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>但我寫入指令與讀取指令之間是丟200ms
<font =“apple-style-span”=”” size=“3”><span =“apple-style-span”=“” style=“line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; “>我猜可能夠PLC反應吧@@~呵呵
<span =“apple-style-span”=”” style="font-size: 12px; font-weight: bold; line-height: 18px; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">
Jay101240647.8547569444

[QUOTE=Jay1012]

並不是I32,而是使用V32
也不是I16,而是使用V16
[/QUOTE]
V32,V16? 有這個格式嗎?

[QUOTE=Jay1012]

並不是I32,而是使用V32
也不是I16,而是使用V16

[/QUOTE]

 

我文章提過的數值格式只有U32和U16,你應該是看錯了。

另外你圖上寫入PLC的字串長度假設都是以最長的資料來換算,傳送時間最快也快要近200ms左右,設200ms在連續執行的程式中可能會有漏失命令的現象。

根據經驗最少設定為估算傳送時間的2倍以上比較不會出錯。

謝謝各位前輩的教導

我真的是看錯了,呵呵