newnet82

MrPLC Member
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About newnet82

  • Rank
    Newbie

Profile Information

  • Country France
  1. FX2N and linux box

    OK, I understand a little more what's happen. First : number greatest than 7999 are special number. In my last post I tried to understand howto create the request for the D500 read. After extracted the 500 I need to convert it in binary 0001 1111 0100 I add a 0 at the end (why ???) 0011 1110 1000 I add a 0100 at the begining (why ???) 0100 0011 1110 1000 I convert it in hex 43E8 and I continue my algorithm. For the 30 32 I sippose it is the size of the data (02 bytes) So, now I can create with a little more understanding request But, it is not enough ... I have again lot of questions (the same as before PLUS new) ...
  2. FX2N and linux box

    Yes I read, again and again, the last version of the manual. In a first time I work in 1:1 situation (it's enough for me for the moment :)) Now, after some tests, I can read each data between D0000 and D7998. My algorithm is : take the data to read (ie D500) extract the integer value (ie 500) use the formule : 16384 + 2 * the extract number (16384 + 2 * 500 = 17384) why 16384 ? For the moment I don't know. But it is (for D values) Convert this number in hex (17384 (dec) = 43E8 (hex)) take the ascii code for each digit (4 => 34; 3 => 33; E => 45; 8 => 38) So the request is : 02 45 30 30 34 33 45 38 30 32 03 45 45 with 02 : STX 45 30 30 : ??? station number + pc number ? It is not the header like they say in the manual page 8.19 30 30 is it the command the a read request ??? 34 33 45 38 is my D500 request 30 32 : ??? 03 : ETX 45 45 => check sum using my checksum algorithm that I give in a previous post And it is Fine I take the contents of the D500 variable. When I want to read the contents of the M500 I need to search again ... But it is not enough. Too much unknown parameters. 16384 ? 45 30 30 ? 30 32 ? .... D8000 and greatest ... If you have answers ... Thx
  3. FX2N and linux box

    Thanks Waynes, your question help me (FX2N-232-BD). after a google search I found a windows serial analyzer (PortmonNt). With it and meldde I can see requests. My linux box can sent request and read answer ! For example, when I want to see the variable D0504 (D0504 = -1) the linux sent : 02, 45, 30, 30, 34, 33, 46, 30, 30, 32, 03, 45, 37 (in hex) the PLC answer's is : 02, 46, 46, 46, 46, 03, 31, 42 (in hex) ie : FFFF => -1 GREAT !!!!!! Now I have an other problem. I don't understand all my query. Can you help me ? In my example the following is what I think understand 02 => STX 45, 30 => station number ???? 30, 34 => PC number ???? 33, 46, 30, 30, 32 => 3F002 ?????????????? D0504 ???????? 03 => ETX 45, 37 => check sum
  4. FX2N and linux box

    Waynes, No, I am communicating to the FX2N via a FX2N-232-BD "extension port"
  5. FX2N and linux box

    Of course Gambit. I'll be happy ... My e-mail id blvq@net6d.com
  6. FX2N and linux box

    In the "user's manual" they give a request to read the type of a station. In hex : 05, 30, 46, 46, 46, 50, 43, 30, 43, 35. I adapted it for my case (I think ;)). So the request becomes : 05, 30, 30, 30, 30, 50, 43, 30, .., .. Regarding the user's manual the http://www.automatas.org/modbus/crc7.html is wrong. For me, it never gives the good LRC. neverthelass I tried the request with this LRC function and the answer was : 06, 15, 15 I used the following code : char *CRC(char *msg) { int sum; int i; char *result; // I do the sum in decimal sum = 0; i = 0; while(msg) { sum += msg[i++]; } result = (char *)malloc(5 * sizeof(char)); // I translate decimal to hexadecimal sprintf(result, "%x\0", sum); // I need only the 2 last characters while(strlen(result) > 2) { result++; } return(result); } Regarding the "user's manual", I always got the good CRC (the same as their). So I tried the request 05, 30, 30, 30, 30, 50, 43, 30, 38, 33 And the answer is again : 06, 15, 15. Is the error because I use the protocol format 1 ? Any ideas ? BR
  7. FX2N and linux box

    Yes I got a 06 (hex) when I send a 05 (hex). But after ... Tx for your help
  8. FX2N and linux box

    Of course no. Meldde is not running under linux. I just tried your sample by writing the C-programm following : --------------------------- BEGIN OF THE C CODE ------------------------------------------ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <termios.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main (int argv, char *argc[]) { int fd; char header[250]; char *line; int c; struct termios term_o; if ((fd = open(argc[1], O_RDWR | O_NOCTTY | O_NONBLOCK )) > 0) { printf("open serial port %s\n", argc[1]); } else { printf("Cannot open serial Port %s\n", argc[1]); return 0; } fcntl(fd, F_SETFL, FNDELAY); /*get current term_o for the port*/ tcgetattr(fd, &term_o); /*set baud rates to 9600*/ cfsetispeed(&term_o, B9600); cfsetospeed(&term_o, B9600); term_o.c_cflag = CLOCAL | CREAD | PARENB | CS7 ; /* this will set new line as carriage return*/ term_o.c_oflag |=ONLCR; printf("c_iflag = %d\n", term_o.c_iflag); printf("c_oflag = %d\n", term_o.c_oflag); printf("c_cflag = %d\n", term_o.c_cflag); printf("c_lflag = %d\n", term_o.c_lflag); tcsetattr(fd, TCSANOW, &term_o); line = (char *) malloc(255 * sizeof(char)); header[0] = 0x05; header[1] = '\0'; int i = 0; printf("line to write -> "); while (i < strlen(header)) { printf("%x, ", header); i++; } printf("\n"); c = write(fd, header, strlen(header)); sleep(1); read(fd, line, 255); i = 0; printf("line read <- "); while (i < strlen(line)) { printf("%x, ", line); i++; } printf("\n"); //02 30 30 30 30 3A 30 32 03 36 36 header[0] = 0x02; header[1] = 0x30; header[2] = 0x30; header[3] = 0x30; header[4] = 0x30; header[5] = 0x3A; header[6] = 0x30; header[7] = 0x32; header[8] = 0x03; header[9] = 0x36; header[10] = 0x36; header[11] = '\0'; i = 0; printf("line to write -> "); while (i < strlen(header)) { printf("%x, ", header); i++; } printf("\n"); c = write(fd, header, strlen(header)); sleep(1); while (1) { if ((i = read(fd, line, 255)) > 0) { printf("Nb Byte read = %d\n", i); i = 0; printf("<- "); while (i < strlen(line)) { printf("%x, ", line); i++; } printf("\n"); } } close(fd); } --------------------------- END OF THE C CODE ------------------------------------------ all what I have is : open serial port /dev/ttyS1 c_iflag = 0 c_oflag = 4 c_cflag = 2464 c_lflag = 0 line to write -> 5, line read <- 6, line to write -> 2, 30, 30, 30, 30, 3a, 30, 32, 3, 36, 36, Nb Byte read = 1 <- 15, And that's all. Why the FX2N sent a NACK ? Where is the error ?
  9. FX2N and linux box

    Hi, I need to use a linux box with a perl programm (or a C programm) in order to communicate with a FX2N. When I send the "windows meldde welcome message" (ie, in hexa, AA, B0, AA, B0, AA, B0, 05, 05, 05) the FX2N never answer the response it done with the "widows meldde" (ie, in hexa, 43, 35, 45, 03, 46, 39). I suppose I have a mistake in the serial port configuration. I tried to do this with : baud / bits / parity / stop 9600 / 7 / O / 1 / 9600 / 7 / E / 1 / 9600 / 7 / O / 2 / 9600 / 7 / E / 2 / 9600 / 8 / O / 1 / 9600 / 8 / E / 1 / 9600 / 8 / O / 2 / 9600 / 8 / E / 2 / Thx for your help