Modbus to Hal

More
14 Nov 2013 00:44 #40793 by andypugh
Replied by andypugh on topic Modbus to Hal

mb2hal does not exist in the thread/functions section in "display HAL". shouldn't it be in the servo thread to get the input/output read? Is there a "addf" missing somewhere ? :).


It is a user-space program (loadusr not loadrt) so it runs on its own internal schedule, rather than linked to a thread.

I am moderately sure that LinuxCNC should be the Master.

But you now know more than me on this subject :-)

Please Log in or Create an account to join the conversation.

More
14 Nov 2013 19:33 #40822 by simon n.
Replied by simon n. on topic Modbus to Hal
Hey Andy,

we want to test the communication between our laptop and linuxcnc over ethernet with modbus/TCP protocol. The laptop is standard windows based. We use Wireshark to monitor the communication between these two components. the tool "modbus slave" is installed on the laptop. We set the port to 502 on the laptop and opened all ports on the linuxcnc pc with the iptable function. We also set the right IP in the .ini from the slave laptop. the laptop is server/slave, the linuxcnc pc is the client/master. We disabled the firewall from the laptop.

When we monitor the communication between laptop and the linuxcnc pc while we start linuxcnc, wireshark shows some stuff which is very confusing. We guess the black lines with the "exception returned" maybe the problem:

s7.directupload.net/file/d/3441/jlc9tep5_png.htm

The laptop is sending data but it doesn't receive any. in this picture the ip ending with 237 is the laptop and the 236 is the linuxcnc pc. Is there a way to see the network with all its participants? we are not sure if these 2 really are the only ones in this network although the laptop is directly connected to the linuxcnc pc via ethernet. Do we have to open more ports somewhere or anything else to get these two components talking to each other?

greetings

Simon N.

Please Log in or Create an account to join the conversation.

More
14 Nov 2013 20:16 #40823 by andypugh
Replied by andypugh on topic Modbus to Hal

Hey Andy, we want to test the communication between our laptop and linuxcnc over ethernet with modbus/TCP protocol..


I am afraid that I really have no idea, I have never used Modbus.

You might have to ask on the mailing list, I believe that Victor Rocco is there, but not here.

Please Log in or Create an account to join the conversation.

More
14 Nov 2013 21:30 #40825 by Todd Zuercher
Replied by Todd Zuercher on topic Modbus to Hal
My only experiance with mb2hal is using modbus RTU not TCPIP. Perhaps it would shed some light on things if you shared you mb2hal.ini file and maybe your hal config files as well. The ini file tells mb2hal what registers to read and write to on the slaves, and configures the pins in the hal file that set what is read and written to those. If you don't have the specific items on your network that you have configured it probably won't do anything. I am pretty sure that mb2hal has absolutly nothing automatic to detect what is on your network, so you have to configure it all in the ini file.

Please Log in or Create an account to join the conversation.

More
14 Nov 2013 22:37 - 14 Nov 2013 23:19 #40830 by simon n.
Replied by simon n. on topic Modbus to Hal
Hi Todd,

i guess your right, we changed the registers in the transaction section. Now at least the write multiple coils works, we now can setp outputs in linuxcnc and it will be displayed on the laptop! But we cannot set a bit on the laptop which is shown in linuxcnc. the num_error for outputs is 0, so we can assume that the output is working fine, what is also the case right now. But the num_error for the inputs is rising steadily, so we assume that its not working.

ini cutout mb2hal:
#This .INI file is also the HELP, MANUAL and HOW-TO file for mb2hal.

 #Load the modbus HAL userspace module as the examples below,
 #change to match your own HAL_MODULE_NAME and .ini file name
 #Using HAL_MODULE_NAME=mb2hal or nothing (default): loadusr -W mb2hal config=config_file.ini
 #Using HAL_MODULE_NAME=mymodule: loadusr -Wn mymodule mb2hal config=config_file.ini

 #Common section

[MB2HAL_INIT]

 #OPTIONAL: Debug level of init and INI file parsing.
 # 0 = silent.
 # 1 = error messages (default).
 # 2 = OK confirmation messages.
 # 3 = debugging messages.

INIT_DEBUG=3

 #OPTIONAL: HAL module (component) name. Defaults to "mb2hal".

HAL_MODULE_NAME=mb2hal

 #OPTIONAL: Insert a delay of "FLOAT seconds" between transactions in order
 #to not to have a lot of logging and facilitate the debugging.
 #Usefull when using DEBUG=3 (NOT INIT_DEBUG=3)
 #It affects ALL transactions.
 #Use "0.0" for normal activity.

SLOWDOWN=0.0

 #REQUIRED: The number of total Modbus transactions. There is no maximum.

TOTAL_TRANSACTIONS=9

 #One transaction section is required per transaction, starting at 00 and counting up sequentially.
 #If there is a new link (not transaction), you must provide the REQUIRED parameters 1st time.
 #Warning: Any OPTIONAL parameter not specified are copied from the previous transaction.

[TRANSACTION_00]

 #REQUIRED: You must specify either a "serial" or "tcp" link for the first transaction.
 #Later transaction will use the previous transaction link if not specified.

LINK_TYPE=tcp

 #if LINK_TYPE=tcp then REQUIRED (only 1st time): The Modbus slave device ip address.
 #if LINK_TYPE=serial then IGNORED

#Laptop IP
TCP_IP=169.254.60.4

 #if LINK_TYPE=tcp then OPTIONAL.
 #if LINK_TYPE=serial then IGNORED
 #The Modbus slave device tcp port. Defaults to 502.

TCP_PORT=502

 #if LINK_TYPE=serial then REQUIRED (only 1st time).
 #if LINK_TYPE=tcp then IGNORED
 #The serial port.

SERIAL_PORT=/dev/ttyS0

 #if LINK_TYPE=serial then REQUIRED (only 1st time).
 #if LINK_TYPE=tcp then IGNORED
 #The baud rate.

SERIAL_BAUD=115200

 #if LINK_TYPE=serial then REQUIRED (only 1st time).
 #if LINK_TYPE=tcp then IGNORED
 #Data bits. One of 5,6,7,8.

SERIAL_BITS=8

 #if LINK_TYPE=serial then REQUIRED (only 1st time).
 #if LINK_TYPE=tcp then IGNORED
 #Data parity. One of: even, odd, none.

SERIAL_PARITY=none

 #if LINK_TYPE=serial then REQUIRED (only 1st time).
 #if LINK_TYPE=tcp then IGNORED
 #Stop bits. One of 1, 2.

SERIAL_STOP=2

 #if LINK_TYPE=serial then OPTIONAL:
 #if LINK_TYPE=tcp then IGNORED
 #Serial port delay between for this transaction only.
 #In ms. Defaults to 0.

SERIAL_DELAY_MS=10

 #REQUIRED (only 1st time).
 #Modbus slave number.

MB_SLAVE_ID=1

 #REQUIRED: The first element address.

FIRST_ELEMENT=1

 #REQUIRED: The number of elements.

NELEMENTS=1

 #REQUIRED: Modbus transaction function code (see www.modbus.org specifications).
 #    fnct_02_read_discrete_inputs     (02 = 0x02)
 #    fnct_03_read_holding_registers   (03 = 0x03)
 #    fnct_04_read_input_registers     (04 = 0x04)
 #    fnct_15_write_multiple_coils     (15 = 0x0F)
 #    fnct_16_write_multiple_registers (16 = 0x10)

 #fnct_02_read_discrete_inputs: creates boolean output HAL pins.
 #fnct_03_read_holding_registers: creates a floating point output HAL pins.
 #                           also creates a u32 output HAL pins.
 #fnct_04_read_input_registers: creates a floating point output HAL pins.
 #                         also creates a u32 output HAL pins.
 #fnct_15_write_multiple_coils: creates boolean input HAL pins.
 #fnct_16_write_multiple_registers: creates a floating point input HAL pins.

 #The pins are named based on component name, transaction number and order number.
 #Example: mb2hal.00.01 (transaction=00, second register=01 (00 is the first one))

MB_TX_CODE=fnct_03_read_holding_registers

 #OPTIONAL: Response timeout for this transaction. In INTEGER ms. Defaults to 500 ms.
 #This is how much to wait for 1st byte before raise an error.

MB_RESPONSE_TIMEOUT_MS=500

 #OPTIONAL: Byte timeout for this transaction. In INTEGER ms. Defaults to 500 ms.
 #This is how much to wait from byte to byte before raise an error.

MB_BYTE_TIMEOUT_MS=500

 #OPTIONAL: Instead of giving the transaction number, use a name.
 #Example: mb2hal.00.01 could become mb2hal.plcin.01
 #The name must not exceed 32 characters.
 #NOTE: when using names be careful that you dont end up with two transactions
 #usign the same name.

HAL_TX_NAME=remoteIOcfg

 #OPTIONAL: Maximum update rate in HZ. Defaults to 0.0 (0.0 = as soon as available = infinit).
 #NOTE: This is a maximum rate and the actual rate may be lower.
 #If you want to calculate it in ms use (1000 / required_ms).
 #Example: 100 ms = MAX_UPDATE_RATE=10.0, because 1000.0 ms / 100.0 ms = 10.0 Hz

MAX_UPDATE_RATE=0.0

 #OPTIONAL: Debug level for this transaction only.
 #See INIT_DEBUG parameter above.

DEBUG=1

 #While DEBUGGING transactions note the returned "ret[]" value correspond to:
 #/* Modbus protocol exceptions */
 #ILLEGAL_FUNCTION        -0x01 the FUNCTION code received in the query is not allowed or invalid.
 #ILLEGAL_DATA_ADDRESS    -0x02 the DATA ADDRESS received in the query is not an allowable address for the slave or is invalid.
 #ILLEGAL_DATA_VALUE      -0x03 a VALUE contained in the data query field is not an allowable value or is invalid.
 #SLAVE_DEVICE_FAILURE    -0x04 SLAVE (or MASTER) device unrecoverable FAILUER while attemping to perform the requested action.
 #SERVER_FAILURE          -0x04 (see above).
 #ACKNOWLEDGE             -0x05 This response is returned to PREVENT A TIMEOUT in the master.
 #                              A long duration of time is required to process the request in the slave.
 #SLAVE_DEVICE_BUSY       -0x06 The slave (or server) is BUSY. Retrasmit the request later.
 #SERVER_BUSY             -0x06 (see above).
 #NEGATIVE_ACKNOWLEDGE    -0x07 Unsuccessful programming request using function code 13 or 14.
 #MEMORY_PARITY_ERROR     -0x08 SLAVE parity error in MEMORY.
 #GATEWAY_PROBLEM_PATH    -0x0A (-10) Gateway path(s) not available.
 #GATEWAY_PROBLEM_TARGET  -0x0B (-11) The target device failed to repond (generated by master, not slave).
 #/* Program or connection */
 #COMM_TIME_OUT           -0x0C (-12)
 #PORT_SOCKET_FAILURE     -0x0D (-13)
 #SELECT_FAILURE          -0x0E (-14)
 #TOO_MANY_DATAS          -0x0F (-15)
 #INVALID_CRC             -0x10 (-16)
 #INVALID_EXCEPTION_CODE  -0x11 (-17)

[TRANSACTION_01]
MB_TX_CODE=fnct_02_read_discrete_inputs
FIRST_ELEMENT=1
NELEMENTS=24
HAL_TX_NAME=remoteIOin
MAX_UPDATE_RATE=0.0
DEBUG=1

[TRANSACTION_02]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=4100
NELEMENTS=24
HAL_TX_NAME=remoteIOout
MAX_UPDATE_RATE=0.0

[TRANSACTION_03]
LINK_TYPE=serial
SERIAL_PORT=/dev/ttyS0
SERIAL_BAUD=115200
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=2
SERIAL_DELAY_MS=50
MB_SLAVE_ID=1
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=1
NELEMENTS=2
HAL_TX_NAME=XDrive01
MAX_UPDATE_RATE=0.0
DEBUG=1

[TRANSACTION_04]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=4
NELEMENTS=3
HAL_TX_NAME=XDrive02
MAX_UPDATE_RATE=0.0
DEBUG=1

[TRANSACTION_05]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=9
NELEMENTS=1
HAL_TX_NAME=XDrive03
MAX_UPDATE_RATE=0.0

[TRANSACTION_06]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=1024
NELEMENTS=1
HAL_TX_NAME=XDrive04
MAX_UPDATE_RATE=0.0

[TRANSACTION_07]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=1030
NELEMENTS=2
HAL_TX_NAME=XDrive05
MAX_UPDATE_RATE=0.0

[TRANSACTION_08]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=1033
NELEMENTS=1
HAL_TX_NAME=XDrive06
MAX_UPDATE_RATE=0.0


We didn't change the HAL-file, we just changed setting in the ini file, at least the mb2hal part. For us the transaction_01 and transaction_02 are very important, because we just want to read/write digital signals. We also tried function 04 for analog signal to read, but when we set some values it won't show up in linuxcnc, the error_num is rising steadily.

Maybe we need to insert the ID from linuxcnc in the transaction_01? because 4100 is from the laptop and that worked in this direction.

Hope you can understand my problem, my english is not the best.



Greetings

Simon N.
Last edit: 14 Nov 2013 23:19 by simon n..

Please Log in or Create an account to join the conversation.

More
14 Nov 2013 23:21 - 14 Nov 2013 23:39 #40831 by simon n.
Replied by simon n. on topic Modbus to Hal
Hey,

we did it! Its working!. The plc sends bits and receives bits. Both are displayed in linuxcnc now! You just have to set the first element in the transaction right, if you want to start with the first bit you have to set first element to 0 and not 1024. If 1024 stays, the first 1024 bits on the modbus will be ignored. When you set output 00 TRUE in linuxcnc the bit 1024 on the modbus will be set TRUE.

Thanks a lot guys

Greetings

Simon N.
Last edit: 14 Nov 2013 23:39 by simon n..

Please Log in or Create an account to join the conversation.

More
23 Nov 2013 01:20 #41118 by VNR
Replied by VNR on topic Modbus to Hal

You might have to ask on the mailing list, I believe that Victor Rocco is there, but not here.


That's right, i feel i am late again.
I usually read the mailing list every day (only the email titles) but the forum once a month.
So don't hesitate to contact me directly by email, saying "i need some help" or "somebody need you in the forum" it is about mb2hal.

Victor

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum