Sign in to follow this  
Followers 0
trm

RS2 requeset then RS2 response

15 posts in this topic

I need to receive a request and then send a response through a RS485 (FX3U-485ADP-MB). I can send, i can receive and i can simultaneously receive and send, but when i try to first receive and then send it doesn't work .... ;( or at least not the way i want. Here is one of my code i think is closest to what i want LD M8000 OUT Y0 // just to see it's working MOV H1C81 D370 // at first i made it bit by bit, but then for more readable code i decided to be a hex value MOV D370 D8400 // write it to CH1 MOV K64 D11 // init. a variable which we will send as test ack LDI M8002 // when not first scan ANI M8402 // and all data has been sent or no data are sending right now RS2 D0 K0 D21 K10 K1 // start waiting to receive 10 bytes LD M8403 // check if received is complete BMOVP D21 D31 D8403 // if yes move data to another buffer (just for testing) MOVP K1 D10 // set D10 to 1 , which is used latter as byte count to send INV // invert it MOV K0 D10 // if M8403 was 1(data available so send response) , but after the INV it's 0 so the line is not executed and D10 = 1 -------------------\ // if M8403 was 0 (data not available so we have not to send response) and after the INV it's 1 so the line is executed D10 = 0 ---------- _this_algorithm_works_ ! LD M8403 // here i could use INV , but decided to be again LD M8403 for more readable code ;) nothing that the code is just for testing. RST M8403 // clear so we are ready for next reception (and this will happen after response is send) LDI M8002 // when not first tart ANI M8403 // and the data was received or no data was received AND> D10 H0 // and there is an value in D10 greater than 0, i.e send some bytes RS2 D11 D10 D0 K0 K1 // start waiting for send request ... to send 1 byte SET M8402 // send request I spent already around 4 or 5 hours in this stupid , easy issue ... i feel ridiculous. Thank you for all your help and time you spent on my problem in advance ! I really appreciate it !

Share this post


Link to post
Share on other sites
Here is another one that has to work , but does not :( LD M8002 OUT Y0 MOV H1C81 D370 MOV D370 D8400 MOV K12 D10 MOV H0103 D11 MOV H0801 D12 MOV H0203 D13 MOV H0405 D14 MOV H0607 D15 MOV H0800 D16 SWAP D11 SWAP D12 SWAP D13 SWAP D14 SWAP D15 SWAP D16 LDI M8402 OUT M0 RS2 D0 K0 D20 K1 K1 LD M8403 OUT M1 MOV D20 D30 RST M8403 RS2 D11 D10 D0 K0 K1 OUT M2 SET M8402 M0 always stays 1 and M1,M2 always 0 I think at start M8002 = 1 => init of CH1, loading data regs with message, after that if M8402 = 0 then set M0 and set RS2 to receive after this when M8403 = 1 (i.e bytes are received) set M1 and mov the received byte into other buffer reset/clear M8403 (i.e = 0) set RS2 set M2 (it's just for checking/debugging) set M8402 for send Maybe after i clear M8403 with the RST instruction my accumulator becomes 0 ?

Share this post


Link to post
Share on other sites
Do you always write your code in IL, or have you just copied the IL code from your programming tool?? Do you have the possibility to post the code in ladder (GX Developer/GX IEC Developer/GX Works)?

Share this post


Link to post
Share on other sites
I always write in IL , but sometimes use Ladder module ... If you want i can make the IL into Ladder and give it to you , but it has to happen later, cause now i'm on a deadline :|

Share this post


Link to post
Share on other sites
GX IEC Developer 7.04 and FX3U plc. after few minutes i will upload the last code i wrote in ladder for GX Developer 8, which has to work , but again does not :( I have both GX IEC Developer , GX Developer ... and also GX Simulator 6 ...

Share this post


Link to post
Share on other sites
Hi again. Check out this function block. I know the function block is for BD card, but RS and RS2 are quite similar, so check out the function block and maybe you can use/modify something in your application. http://www.beijer.no/web/web_aut_no.nsf/docsbycodename/filearchive?OpenDocument&mylink=/web/BExFilePileAUT.nsf/fm.be.searchframe?Openform&Lang=NO&DocID=46B82E00767FA7A1C125728E005D1FBA

Share this post


Link to post
Share on other sites
Here it is ... I wrote the program in IL in GX IEC Developer 7.04 and then looking at it i wrote it in Ladder in GX Developer 8 So the attached file is a project for GX Developer and it is in Ladder ;) Thank you a lot for your time and answers ! :) request_response_v1.rar

Share this post


Link to post
Share on other sites
Here is another code that does one request receive and then response send Now the question is what to add so it does it only one send per request. There are few options i can think of: 1. check M8403 , if 1 then we have receive complete = i.e bytes received so we process the request and send the response 2. check D8403 , if >0 then we have receive x number of bytes 3. check first buffer reg, i.e if RS2 D0 K0 D21 D20 K1 then D21 is the first buffer register and we check if it has changed or it has a value different than 0 , if yes then we have (new) request :) ---- I have tried all of this variant .. including using/making a flag (M0/M1/M2/M3/... etc) for the different states, but with no success so far ... And i know this is a very stupid and funny problem ! ;) :) LD M8002 //on first scan OUT Y0 //test output on MOV H1C81 D370 // CH1 config MOV D370 D8400 // init CH1 MOV K8 D20 // bytes count to be received MOV K3 D10 // bytes count that for sure will be send MOV H0102 D14 // just dummy bytes of data MOV H0304 D15 // same MOV H0506 D16 // same MOV H0708 D17 // same LD M8000 //non-stop working/receiving as there can be multiple requests from different clients RS2 D0 K0 D21 D20 K1 // send nothing , receive 8 bytes in D21-24 regs (cause 8bytes = 4 word) LD M8403 // if receive complete WAND H00FF D21 D31 // get lower byte WAND HFF00 D21 D32 // get high byte SWAP D32 // switch MSG, LSB so the reg represent the actual value (i.e 0x0900 is actualy 0x0009 -> decimal 9, because we receive in 8 bit mode but store in 16 bit registers D... ) MOV D23 D33 // copy value (this is due to the protocol i use RTU Modbus) SWAP D33 // FX3U-485ADP-MB sends in LITTLE ENDIAN for unknown reasons and i don't find a setting/bit to change that , so we have to switch MSB/LSB to send the high byte first ! :) LD= D31 H1 // if unit = 1 AND= D32 H3 // if function code = 3 OUT M0 // flag M0 is ON LD M0 // if flag for correct request is on MOV D31 D11 // full buffer (id) MOV D32 D12 // same (function code) MUL D33 H2 D13 // we have X words requested * 2 bytes each = x*2 (length of data frame) MOV D10 D30 // move constant byte count for send (id + fc + length = 3) ADD D13 D30 D30 // add the count of the date bytes = x * 2 (we already calculated this above) RS2 D11 D30 D0 K0 K1 // send from reg D11 , D30 count of registers , no receiving SET M8402 // send request to _SERIAL_MODULE_CH1 Thank you for your time ... bye for now ;) :) ps: GX simulator can not simulate serial communication / module ;( :( Edited by trm

Share this post


Link to post
Share on other sites
Hi trm, I have not tested it, just some input for you to hopefully getting forward. Best regards Dariusch

Share this post


Link to post
Share on other sites
Hi ! Thanks ! Something very important i have realized yesterday ((but have forgotten today) when going back to home and thinking it through. And now it came back to me: Not the 'Send Request' must be constantly true , the RS2 instruction must be ! I.e you can have only one line RS2 and depending on M8402 it will send and receive or only receive ! LD M8002 MOV K65 D11 LD M8000 RS2 D11 K1 D21 K1 K1 LD M0 SET M8402 RST M0 LD M8403 RST M8403 Test it ... through Debug/Online Monitor change the value of M0 to 1 and it will SET M8402 then right away M0 goes 0 It receive every time and sends only when M0 is set :) :) I haven't implement it in my program exactly in this way, but from one hour and so i use only one (1) RS2 instruction and once i have succeeded to send per request ... playing with the M8402 only , how and when to be set .. nothing else and now i remember this , so after the launch break (cause here by me it's 12:51) i think i will finish it. After that i will test your program ! Thanks for you reply !!! btw: The treasure key is in the Pulse instructions and SET (not OUT instruction) ! :) :) ! Edited by trm

Share this post


Link to post
Share on other sites
I have test your code Dariusch, it does not send .. it receives the request ,but does not send ;) i have no time to debug it right now , but maybe next week I will develop this code: LD M8002 _initialization_ LD M8000 RS2 D11 K1 D21 K1 K1 LD M0 // flag send SET M8402 RST M0 // right after send request is set clear flag (the send request already have gone on it's way) LD M8403 // if we have received SET M1 // set receive flag _collect_data_ // move to _more_user_buffer (cause the buffer we have in the RS2 line we have dedicated to the communication which happens every scan ! :) RST M8403 // clear receive flag --- I will write to you as soon as it works right and give you the code ...

Share this post


Link to post
Share on other sites
I needed this request -> response as an optional feature ... , but ... as of now i have two working codes with such kind of 'behavior' (and not working very well). 1. receiving request and sending correct response many times before stopping :| [ i will not put the code , cause it's not worth ed ] 2. receiving 5-7 bytes and then sending one ... LD M8002 MOV K1 D10 MOV K65 D11 LD M8000 RS2 D11 D10 D21 K10 K1 LD M8403 SET M0 RST M8403 LDP M0 SET M8402 RST M0 -- The device i'm working on actualy it's going to be Serial RTU Modbus Master and Ethernet TCP Modbus Slave , but i wanted and my bosses wanted to be able to respond and to RTU Modbus requests on the rserial port(s) ... but it will have to be developed on a later stage ... Thank you for all your help and time spent ! I leave the subject open and when i have the time i will write here. Yet again i'm sure we are missing something small , not mentioned in the documentation , which i read not just serveral but many times - especially the part about RS2 communicaiton ! :( I think this is a stupid problem ... and some skilled PLC programmer will actually laugh at us , but i'm not worried about that, i'm worried about the time I/we spent for such easy task (or at least easy at first sight). Good Luck and have a nice weekend (it's 16 o'clock by me so i have 3 more hours of word day ;) :)) Bye.

Share this post


Link to post
Share on other sites
If you're going to communicate via ModbusRTU (either as a slave or as a master) you should check out the already published function blocks (GX IEC Developer) for this purpose..... http://www.beijer.no/web/web_aut_no.nsf/docsbycodename/filearchive?OpenDocument&mylink=/web/BExFilePileAUT.nsf/fm.be.searchframe?Openform&Lang=NO&DocID=1072A50FA9CEEAE9C12573C4004E3A25

Share this post


Link to post
Share on other sites
But yet it's only a implementation of the modbus protocol , it doesn't handle the actual sending and receiving ;) where is my problem when i'm acting like slave (RTU Modbus). And i already have writen my own modbus implementation for Master (cause i use only few of the available Function Codes ;) ) But Thanks ! That's really a useful information ;) :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0