plcpeople / mcprotocol

node.js implementation of the MC (MELSEC communication) protocol to exchange data with Mitsubishi FX programmable controllers.
MIT License
99 stars 40 forks source link

Fx5-U Connection Issues #4

Closed programlayan closed 4 years ago

programlayan commented 4 years ago

Hello, I tried to connect FX-5U with mcprotocol. (With default ethernet configuration) Connected but timeout occured. (Port 1280 used) When I try to add SLMP and port 1281 connection refused. What can I do for connection? thank you.

--default configuration full output -- osboxes@osboxes:~/Desktop/plc$ node index.js [13654,472511518] Initiate Called - Connecting to PLC with address and parameters: [13654,474872590] { port: 1280, host: '192.168.11.253', ascii: false } [13654,476336891] Connection cleanup is happening [13654,476448689 192.168.11.253] Clearing read PacketTimeouts [13654,476540692 192.168.11.253] Clearing write PacketTimeouts [13654,477061769 192.168.11.253] [13654,477157964 192.168.11.253] Attempting to connect to host... [13654,479260801 192.168.11.253] TCP Connection Established to 192.168.11.253 on port 1280 [13654,479759896] Translation OK [13654,479902438 192.168.11.253] Reading All Items (readAllItems was called) [13654,480222241 192.168.11.253] Adding or Removing { arg: [ 'TEST1' ], action: 'add' } [13654,480343069 192.168.11.253] Adding TEST1 [13654,481492403 192.168.11.253] Clearing read PacketTimeouts [13654,481623624 192.168.11.253] Calling SRP from RAI [13654,481789472 192.168.11.253] SendReadPacket called [13654,481951201] We're Binary [13654,482263745] The Returned MC Buffer is: [13654,482325446] <Buffer 01 ff 0a 00 00 00 00 00 20 4d 01 00> [13654,482583582] The returned buffer length is 12 [13654,482715223] The final send buffer is: [13654,482768884] <Buffer 01 ff 0a 00 00 00 00 00 20 4d 01 00> [13654,483404295] Sending Read Packet SEQ 2 [13658,989687579 192.168.11.253] PacketTimeout called with type read and seq 2 [13658,989849586 192.168.11.253] READ TIMEOUT on sequence number 2 [13658,990198258 192.168.11.253] ReadResponse called [13658,990618274] Timeout error - zero length packet [13658,990728828 192.168.11.253] Read Time is 4 seconds and 508.9 ms. [13658,990995231 192.168.11.253] Every packet done sending [13658,991520979] Logging a Bad Quality thePointer 0 [13658,991625825] Logging a Bad Quality thePointer 0 [13658,991704333] Logging a Bad Quality thePointer 0 [13658,991773858] Logging a Bad Quality thePointer 0 [13658,991837977] Logging a Bad Quality thePointer 0 [13658,991892822 192.168.11.253] Address M0,5 has value false,false,false,false,false and quality BAD 255,BAD 255,BAD 255,BAD 255,BAD 255 [13658,991984928 192.168.11.253] We are calling back our readDoneCallback. SOMETHING WENT WRONG READING VALUES!!!! { TEST1: [ 'BAD 255', 'BAD 255', 'BAD 255', 'BAD 255', 'BAD 255' ] } -- end output --

plcpeople commented 4 years ago

I think the only way this will work with your CPU is if we add support for 3E frames. (Or another type, but 3E looks like it would support the most additional CPU types). I would be willing to do a bit of work on this but I don't have a test CPU other than an FX3U so I think the only way we could make this work is if someone else had some time and a test CPU to help get it working. I will see what I can do in the next week or two.

programlayan commented 4 years ago

Hello, Thank you for your response, I can test, also if you want to test too, I can send a remote connection for testing purposes too. Thank you.

plcpeople commented 4 years ago

OK I pushed a new version to the repository (but not to npm), and it seems to send the right packet in both ASCII and binary to read device memory. To activate the new code add connection options frame: '3E' and it would help if you added debug: true as well.

Use care in testing on a real PLC. I've tried to be careful but I have no way of testing these frames on a real CPU.

programlayan commented 4 years ago

Hello, Thank you, I will try it, but Covid-19 reasons I am out of office since 6 April.

plcpeople commented 4 years ago

OK, let me know. COVID-19 is the reason I had time to work on this. Hopefully by 6 April things are better everywhere.

programlayan commented 4 years ago

Hello I tried new code: .. var variables = { TEST1: 'D100,1'}; .. conn.initiateConnection({port: 1280, host: '192.168.3.249', ascii: false}, connected);

Tried read value only.

---- result ---- [60450,48886812] Initiate Called - Connecting to PLC with address and parameters: [60450,52312441] { port: 1280, host: '192.168.3.249', ascii: false } [60450,53998936] Connection cleanup is happening [60450,54141153 192.168.3.249] Clearing read PacketTimeouts [60450,54258652 192.168.3.249] Clearing write PacketTimeouts [60450,54976305 192.168.3.249] [60450,55065257 192.168.3.249] Attempting to connect to host... [60450,63583727 192.168.3.249] TCP Connection Established to 192.168.3.249 on port 1280 [60450,64181292] Translation OK [60450,64419024 192.168.3.249] Reading All Items (readAllItems was called) [60450,64910022 192.168.3.249] Adding or Removing { arg: [ 'TEST1' ], action: 'add' } [60450,65090850 192.168.3.249] Adding TEST1 [60450,67048255 192.168.3.249] Clearing read PacketTimeouts [60450,67250386 192.168.3.249] Calling SRP from RAI [60450,67504775 192.168.3.249] SendReadPacket called [60450,67770238] We're Binary [60450,68163393] The Returned MC Buffer is: [60450,68294859] <Buffer 01 ff 0a 00 64 00 00 00 20 44 01 00> [60450,68692612] The returned buffer length is 12 [60450,68918805] The final send buffer is: [60450,69037367] <Buffer 01 ff 0a 00 64 00 00 00 20 44 01 00> [60450,70302925] Sending Read Packet SEQ 2 [60454,574861407 192.168.3.249] PacketTimeout called with type read and seq 2 [60454,575049782 192.168.3.249] READ TIMEOUT on sequence number 2 [60454,575412905 192.168.3.249] ReadResponse called [60454,575851273] Timeout error - zero length packet [60454,575987348 192.168.3.249] Read Time is 4 seconds and 508.4 ms. [60454,576356711 192.168.3.249] Every packet done sending [60454,576931988] Item Quality is Bad [60454,577024255 192.168.3.249] Address D100,1 has value 0 and quality BAD 255 [60454,577160105 192.168.3.249] We are calling back our readDoneCallback. SOMETHING WENT WRONG READING VALUES!!!! { TEST1: 'BAD 255' } --- end result ----

D100 value is 21 (word)

I added image SLMP connection https://ibb.co/L1wYTRm

programlayan commented 4 years ago

Ahh sorry, my mistake, I just installed library again from github.

same scenario and the output is:

[64460,616653189] Initiate Called - Connecting to PLC with address and parameters: [64460,619149926] { port: 1280, host: '192.168.3.249', ascii: false } [64460,621206835] Connection cleanup is happening [64460,621375635 192.168.3.249] Clearing read PacketTimeouts [64460,621496513 192.168.3.249] Clearing write PacketTimeouts [64460,622201112 192.168.3.249] [64460,622314207 192.168.3.249] Attempting to connect to host... (node:84955) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. [64460,627958884 192.168.3.249] TCP Connection Established to 192.168.3.249 on port 1280 [64460,628538075] Translation OK [64460,628734891 192.168.3.249] Reading All Items (readAllItems was called) [64460,629150183 192.168.3.249] Adding or Removing { arg: [ 'TEST1' ], action: 'add' } [64460,629325497 192.168.3.249] Adding TEST1 [64460,630556418 192.168.3.249] Clearing read PacketTimeouts [64460,630723052 192.168.3.249] Calling SRP from RAI [64460,630943460 192.168.3.249] SendReadPacket called [64460,632028250] Sending Read Packet SEQ 2 [64465,137629704 192.168.3.249] PacketTimeout called with type read and seq 2 [64465,137829842 192.168.3.249] READ TIMEOUT on sequence number 2 [64465,138159209 192.168.3.249] ReadResponse called [64465,138544487] Timeout error - zero length packet [64465,138676731 192.168.3.249] Read Time is 4 seconds and 507.6 ms. [64465,138929987 192.168.3.249] Every packet done sending [64465,139372529] Item Quality is Bad [64465,139461610 192.168.3.249] Address D100,1 has value 0 and quality BAD 255 [64465,139560061 192.168.3.249] We are calling back our readDoneCallback. SOMETHING WENT WRONG READING VALUES!!!! { TEST1: 'BAD 255' }

plcpeople commented 4 years ago

Try adding frame: '3E' and debug: true in the same object where you specify the port and IP address. It is still sending the same 1E frames as before without the frame option.

programlayan commented 4 years ago

Hello, I added SLMP by PLC, set its Protocol TCP and port 1281. There is no debug option here. (Please copy and paste the URL: https://ibb.co/L1wYTRm ) On the node side, I assigned debuglevel 99 and frame 3E. The current value of D100 is 26.

-- output -- [82843,780524530] Initiate Called - Connecting to PLC with address and parameters: [82843,782854481] { port: 1281, host: '192.168.3.249', ascii: false } [82843,784485046] Connection cleanup is happening [82843,784603726 192.168.3.249] Clearing read PacketTimeouts [82843,784740048 192.168.3.249] Clearing write PacketTimeouts [82843,785440584 192.168.3.249] [82843,785531243 192.168.3.249] Attempting to connect to host... (node:94150) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. [82843,794255431 192.168.3.249] TCP Connection Established to 192.168.3.249 on port 1281 [82843,794759674] Translation OK [82843,794958717 192.168.3.249] Reading All Items (readAllItems was called) [82843,795371469 192.168.3.249] Adding or Removing { arg: [ 'TEST1' ], action: 'add' } [82843,795559936 192.168.3.249] Adding TEST1 [82843,797219263 192.168.3.249] Clearing read PacketTimeouts [82843,797443066 192.168.3.249] Calling SRP from RAI [82843,797673041 192.168.3.249] SendReadPacket called [82843,798043302] We're Binary [82843,798280346] The Returned MC Buffer is: [82843,798364623] <Buffer 50 00 00 ff ff 03 00 0c 00 10 00 01 04 00 00 64 00 00 a8 01 00> [82843,798691667] The returned buffer length is 21 [82843,798906691] The final send buffer is: [82843,798962696] <Buffer 50 00 00 ff ff 03 00 0c 00 10 00 01 04 00 00 64 00 00 a8 01 00> [82843,799728566] Sending Read Packet SEQ 2 [82843,812923792] onResponse called with length 13 [82843,813043531] Valid MC Response Received (not yet checked for error) [82843,813101053] Received 13 bytes of data from PLC. [82843,813148681] <Buffer d0 00 00 ff ff 03 00 04 00 00 00 1a 00> [82843,813253479] Received Read Response [82843,813467445 192.168.3.249] ReadResponse called [82843,813740433] Invalid Response Length - Expected 2 but got 4 bytes. [82843,813819044 192.168.3.249] Read Time is 0 seconds and 16 ms. [82843,813998346 192.168.3.249] Every packet done sending [82843,814309135] Item Quality is Bad [82843,814394360 192.168.3.249] Address D100,1 has value 0 and quality BAD 255 [82843,814521770 192.168.3.249] We are calling back our readDoneCallback. SOMETHING WENT WRONG READING VALUES!!!! { TEST1: 'BAD 255' } -- end output--

plcpeople commented 4 years ago

Ok, please try the latest commit.

Also, if that doesn't work, or if you want more features even if it does, check out this fork at https://github.com/Steve-Mcl/mcprotocol - you should be able to test the file in that version, with frame: '3E' and it should work. We're discussing merging those changes into this project.

programlayan commented 4 years ago

Hello, Thank you for your effort. Results are the same as previous test. I will try other package. Thank you. --output-- [1045,547033914] Initiate Called - Connecting to PLC with address and parameters: [1045,550602868] { port: 1281, host: '192.168.3.249', ascii: false } [1045,552690940] Connection cleanup is happening [1045,552868583 192.168.3.249] Clearing read PacketTimeouts [1045,553022278 192.168.3.249] Clearing write PacketTimeouts [1045,553867865 192.168.3.249] [1045,553972219 192.168.3.249] Attempting to connect to host... (node:4398) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. [1045,561915854 192.168.3.249] TCP Connection Established to 192.168.3.249 on port 1281 [1045,562392937] Translation OK [1045,562629143 192.168.3.249] Reading All Items (readAllItems was called) [1045,563041921 192.168.3.249] Adding or Removing { arg: [ 'TEST1' ], action: 'add' } [1045,563242902 192.168.3.249] Adding TEST1 [1045,564639866 192.168.3.249] Clearing read PacketTimeouts [1045,564984378 192.168.3.249] Calling SRP from RAI [1045,565281138 192.168.3.249] SendReadPacket called [1045,565557652] We're Binary [1045,566157851] The Returned MC Buffer is: [1045,566265216] <Buffer 01 ff 0a 00 64 00 00 00 20 44 02 00> [1045,567027515] The returned buffer length is 12 [1045,567303387] The final send buffer is: [1045,567427051] <Buffer 01 ff 0a 00 64 00 00 00 20 44 02 00> [1045,568357931] Sending Read Packet SEQ 2 [1050,72547850 192.168.3.249] PacketTimeout called with type read and seq 2 [1050,72707900 192.168.3.249] READ TIMEOUT on sequence number 2 [1050,73051774 192.168.3.249] ReadResponse called [1050,73442561] Timeout error - zero length packet [1050,73567700 192.168.3.249] Read Time is 4 seconds and 508.1 ms. [1050,73825249 192.168.3.249] Every packet done sending [1050,74338804] Logging a Bad Quality thePointer 0 [1050,74430855] Logging a Bad Quality thePointer 2 [1050,74511368 192.168.3.249] Address D100,2 has value 0,0 and quality BAD 255,BAD 255 [1050,74626088 192.168.3.249] We are calling back our readDoneCallback. SOMETHING WENT WRONG READING VALUES!!!! { TEST1: [ 'BAD 255', 'BAD 255' ] } --end output--

plcpeople commented 4 years ago

I think you loaded the wrong file when updating as I can tell you're back to 1E frames there.

programlayan commented 4 years ago

Hello I tried Steve-Mcl fork, it is working. Thank you.

hj91 commented 4 years ago

Does it work with ethernet comm based fx5u and Q/L or R series plc?

Is Cc-Link supported?