RS-485 on 5i25+7i76/7i85

More
6 years 4 weeks ago - 6 years 4 weeks ago #184607 by PCW
Replied by PCW on topic RS-485 on 5i25+7i76/7i85
Basically its a structural issue, The HM2 driver was written initially for PCI/PCIE cards
and assumes that random read and writes are inexpensive. Unfortunately this is not
true of HM2 Ethernet. On Ethernet, its expected that only three packets are exchanged every
servo thread invocation. (read-request, read data, write data) Probably what needs to be done
is that the PktUART driver needs to have a state machine so that all access is merged
into these three packets.

For example when a packet data count is read (via the standard read-request/read)
The actual FIFO character data read would have to be deferred to the next servo thread
invocations read-request/read, to avoid doing a random additional read.

I have also considered a firmware/driver change to allow a FIFO readout command
during a read_request
Last edit: 6 years 4 weeks ago by PCW.

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

More
6 years 1 week ago #186710 by rumking
Replied by rumking on topic RS-485 on 5i25+7i76/7i85
Hi Peter,
thank you for the suggestions.

I managed to send some bytes over the line (it seems - the send function returns the number of bytes sent), but I got an error while read:
hm2/hm2_7i76e.0: error finishing read! iter=6

I have read-request, read, write functions added to the servo thread (however, I am not sure about the order of the functions)
addf hm2_7i76e.0.read servo-thread
addf hm2_7i76e.0.read-request servo-thread
addf hm2_7i76e.0.write servo-thread

My realtime component is named dcell_ascii_test. I run the receive function in a thread with 2s period (to be able to track the rtapi_print_msg - which might not be very clever)
loadrt dcell_ascii_test names="hm2_7i76e.0.pktuart.0"

loadrt threads name1=test1 period1=2000000000
addf hm2_7i76e.0.pktuart.0.receive test1

What I am intending to do inside the hm2_7i76e.0.pktuart.0.receive function is to send a frame of 11B - "!001:SOUT?\r" like this:
rtapi_u16 message_length = 11;
rtapi_u16 message_size[1]={message_length,};
rtapi_u8 num_frames = 1;
unsigned char message[1*11] ={
//! 0 0 1 : S O U T ? \r
0x21, 0x30, 0x30, 0x31, 0x3a, 0x53, 0x4f, 0x55, 0x54, 0x3f, 0x0d
};
retval=hm2_pktuart_send(name, message, &num_frames, message_size);
rtapi_print_msg(0, "PktUART send: sent %d bytes\n", retval);

The slave device should then respond with some bytes of data I want to get:
rtapi_u8 num_frames = 1;
rtapi_u16 max_frame_length = 26;
unsigned char Replyd3[num_frames*max_frame_length];
rtapi_u16 frame_sizes3[26];
rxbytes=hm2_pktuart_read(name, Replyd3, &num_frames, &max_frame_length, frame_sizes3);
rtapi_print_msg(RTAPI_MSG_INFO, "PktUART receive: got %d bytes, %d frames\n", rxbytes, num_frames);

Do you have any idea why I get the error?
hm2/hm2_7i76e.0: error finishing read! iter=6

I am not sure if I can do all this inside the hm2_7i76e.0.pktuart.0.receive function (send a request and expect a response).
I think I should aswell set the line to transmit mode when transmitting and to receive mode when reading. But to be honest, I don't know how to work with the transmit enable pin.

Thank you.

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

More
6 years 1 week ago #186717 by PCW
Replied by PCW on topic RS-485 on 5i25+7i76/7i85
You do not need read-request so I would drop that

Because you cannot poll,, the upper layer code must implement a state
machine that does the status polling and determining RX packet sizes by reads
in one servo thread invocation, and the data reads in the next invocation

TXenable is automatic if enabled in the register

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

Moderators: PCW, jmelson
Time to create page: 0.354 seconds
Powered by Kunena Forum