├── Arduino_PLC_Fx1.ino └── Mitsubishi_PLC_FX1S_lib ├── FX1S.cpp ├── FX1S.h ├── README.txt ├── examples └── Mitsubishi_PLC_FX1S │ └── Mitsubishi_PLC_FX1S.ino ├── keywords.txt └── library.properties /Arduino_PLC_Fx1.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the 3 | Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. 4 | The circuit: 5 | * LCD RS pin to digital pin 8 6 | * LCD En pin to digital pin 9 7 | * LCD D4 pin to digital pin 4 8 | * LCD D5 pin to digital pin 5 9 | * LCD D6 pin to digital pin 6 10 | * LCD D7 pin to digital pin 7 11 | * LCD R/W pin to ground 12 | * 10K resistor: 13 | * ends to +5V and ground 14 | * wiper to LCD VO pin (pin 3) 15 | */ 16 | 17 | #include 18 | // initialize the library with the numbers of the interface pins 19 | // RS EN D4 D5 D6 D7 20 | LiquidCrystal lcd( 8, 9, 4, 5, 6, 7); 21 | 22 | 23 | /* 24 | this program writen by Cartiman for program-plc.blogspot.com 25 | No sell and No Complaint 26 | by program-plc.blogspot.com 27 | */ 28 | #include 29 | 30 | /* 31 | #define FX1Sbaud 19200 32 | #define FX1Sformat SERIAL_8N1 33 | #define FX1Stimeout 1000 34 | */ 35 | #define FX1Sbaud 9600 36 | #define FX1Sformat SERIAL_7E1 37 | #define FX1Stimeout 1000 38 | 39 | enum 40 | { 41 | FX1SPACKET1, 42 | FX1SPACKET2, 43 | FX1STOTAL_NO_OF_PACKETS 44 | }; 45 | 46 | FX1SPacket FX1Spackets[FX1STOTAL_NO_OF_PACKETS]; 47 | 48 | FX1SpacketPointer FX1Spacket1 = &FX1Spackets[FX1SPACKET1]; 49 | FX1SpacketPointer FX1Spacket2 = &FX1Spackets[FX1SPACKET2]; 50 | 51 | unsigned int FX1SreadD[1]; 52 | unsigned int FX1SwriteD[1]; 53 | boolean readPLC = true; 54 | unsigned int D0, D1; 55 | #define AnalogInputPin A0 56 | #define AnalogOutputPin 9 57 | 58 | 59 | void setup() 60 | { 61 | Serial.begin(9600); 62 | while (!Serial) 63 | { 64 | ; // wait for serial port to connect. Needed for native USB 65 | } 66 | Serial.println("Serial test"); 67 | Setup_LCD(); 68 | 69 | FX1S_construct(FX1Spacket1, FX1S_READ_D, 0, 1, FX1SreadD); 70 | FX1S_construct(FX1Spacket2, FX1S_WRITE_D, 1, 1, FX1SwriteD); 71 | FX1S_configure(&Serial, FX1Sbaud, FX1Sformat, FX1Stimeout, FX1Spackets, FX1STOTAL_NO_OF_PACKETS); 72 | } 73 | 74 | 75 | void loop() 76 | { 77 | if (readPLC) 78 | { 79 | FX1S_update(); 80 | 81 | //Write to D1 82 | D1 = map(analogRead(AnalogInputPin), 0, 1023, 0, 32767); 83 | FX1SwriteD[0] = D1; 84 | 85 | //Read from D0 86 | D0 = FX1SreadD[0]; 87 | //D0 = map(D0, 0, 32767, 0, 255); 88 | readPLC = false; 89 | } 90 | else 91 | { 92 | /* 93 | * default : 327xx 94 | * Select : 205xx 95 | * Left : 131xx 96 | * Right : 000xx 97 | * Up : 031xx 98 | * Down : 081xx 99 | */ 100 | //lcd.clear(); 101 | lcd.setCursor(0, 0); 102 | lcd.print("Key val: " + String(D1) + " "); 103 | lcd.setCursor(0, 1); 104 | lcd.print("PLC val: " + String(D0) + " "); 105 | readPLC = true; 106 | } 107 | } 108 | 109 | void Setup_LCD() 110 | { 111 | // set up the LCD's number of columns and rows: 112 | lcd.begin(16, 2); 113 | // startup LOGO 114 | lcd.setCursor(4,0); 115 | lcd.print("CNCProVN"); 116 | lcd.setCursor(2,1); 117 | lcd.print("Pham Duy Anh"); 118 | delay(1000); 119 | lcd.clear(); 120 | lcd.setCursor(0,0); 121 | lcd.print("www.cncprovn.com"); 122 | lcd.setCursor(0,1); 123 | lcd.print("Arduino & PLC test"); 124 | delay(1000); 125 | lcd.clear(); 126 | } 127 | 128 | 129 | -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/FX1S.cpp: -------------------------------------------------------------------------------- 1 | #include "FX1S.h" 2 | #include "HardwareSerial.h" 3 | 4 | #define FX1S_ENQ 1 5 | #define FX1S_IDLE 2 6 | #define FX1S_WAITING_FOR_REPLY 3 7 | 8 | 9 | #define FX1S_BUFFER_SIZE 128 10 | 11 | unsigned char FX1Sstate; 12 | 13 | 14 | unsigned char msgframe[FX1S_BUFFER_SIZE]; 15 | unsigned char msgbuffer; 16 | unsigned int FX1Stimeout; 17 | unsigned int FX1S_T1; 18 | unsigned long FX1SdelayStart; 19 | unsigned int FX1S_total_no_of_packets; 20 | FX1SPacket* FX1SpacketArray; 21 | FX1SPacket* FX1Spacket; 22 | HardwareSerial* FX1SPort; 23 | 24 | void FX1Senq(); 25 | void FX1Sidle(); 26 | void FX1SconstructPacket(); 27 | unsigned char construct_FX1S_WRITE_D(); 28 | unsigned char construct_FX1S_READ_D(); 29 | void FX1Swaiting_for_reply(); 30 | void FX1SprocessReply(); 31 | void process_FX1S_READ_D(); 32 | void process_FX1S_WRITE_D(); 33 | void FX1SprocessError(); 34 | void FX1SprocessSuccess(); 35 | void FX1SsendPacket(unsigned char bufferSize); 36 | 37 | unsigned int iBUFF0,iBUFF1; 38 | String sBUFF0,sBUFF1,sBUFF2; 39 | unsigned char ASCII_Normalize(unsigned char ASCII_Val); 40 | bool FX1S_ENQ_PROC; 41 | byte HexCharByte(unsigned char HexChar); 42 | 43 | 44 | void FX1S_update() 45 | { 46 | switch (FX1Sstate) 47 | { 48 | case FX1S_ENQ: 49 | FX1Senq(); 50 | break; 51 | case FX1S_IDLE: 52 | FX1Sidle(); 53 | break; 54 | case FX1S_WAITING_FOR_REPLY: 55 | FX1Swaiting_for_reply(); 56 | break; 57 | } 58 | } 59 | 60 | void FX1Senq() 61 | { 62 | msgframe[0] = ENQ; 63 | FX1SsendPacket(1); 64 | FX1S_ENQ_PROC = true; 65 | FX1Sstate = FX1S_WAITING_FOR_REPLY; 66 | } 67 | 68 | 69 | void FX1Sidle() 70 | { 71 | static unsigned int packet_index; 72 | 73 | unsigned int failed_connections = 0; 74 | 75 | unsigned char current_connection; 76 | 77 | do 78 | { 79 | if (packet_index == FX1S_total_no_of_packets) // wrap around to the beginning 80 | packet_index = 0; 81 | 82 | // proceed to the next FX1Spacket 83 | FX1Spacket = &FX1SpacketArray[packet_index]; 84 | 85 | // get the current FX1Sconnection status 86 | current_connection = FX1Spacket->FX1Sconnection; 87 | 88 | if (!current_connection) 89 | { 90 | // If all the FX1Sconnection attributes are false return 91 | // immediately to the main sketch 92 | if (++failed_connections == FX1S_total_no_of_packets) 93 | return; 94 | } 95 | packet_index++; 96 | 97 | // if a FX1Spacket has no FX1Sconnection get the next one 98 | }while (!current_connection); 99 | 100 | FX1SconstructPacket(); 101 | } 102 | 103 | 104 | void FX1SconstructPacket() 105 | { 106 | FX1Spacket->FX1Srequests++; 107 | FX1Spacket->FX1Serror=99; 108 | 109 | msgframe[0] = STX; 110 | msgframe[1] = FX1Spacket->FNC; 111 | msgframe[2] = 0x31; 112 | 113 | iBUFF0 = FX1Spacket->ADDR * 2; 114 | sBUFF0 = "000" + String(iBUFF0, HEX); 115 | sBUFF0.toUpperCase(); 116 | iBUFF1 = sBUFF0.length()-3; 117 | sBUFF2 = sBUFF0.substring(iBUFF1); 118 | 119 | msgframe[3] = sBUFF2[0]; 120 | msgframe[4] = sBUFF2[1]; 121 | msgframe[5] = sBUFF2[2]; 122 | 123 | 124 | iBUFF0 = FX1Spacket->SIZE * 2; 125 | sBUFF0 = "00" + String(iBUFF0, HEX); 126 | sBUFF0.toUpperCase(); 127 | iBUFF1 = sBUFF0.length()-2; 128 | sBUFF2 = sBUFF0.substring(iBUFF1); 129 | 130 | msgframe[6] = sBUFF2[0]; 131 | msgframe[7] = sBUFF2[1]; 132 | 133 | unsigned char frameSize; 134 | 135 | if (FX1Spacket->FNC == FX1S_WRITE_D) { 136 | frameSize = construct_FX1S_WRITE_D(); 137 | }else if (FX1Spacket->FNC == FX1S_READ_D){ 138 | frameSize=construct_FX1S_READ_D(); 139 | } 140 | 141 | FX1SsendPacket(frameSize); 142 | FX1Sstate = FX1S_WAITING_FOR_REPLY; 143 | } 144 | 145 | unsigned char construct_FX1S_WRITE_D() 146 | { 147 | 148 | unsigned char no_of_D = FX1Spacket->SIZE; 149 | unsigned char index = 8; 150 | 151 | for (unsigned char i = 0; i < no_of_D; i++) 152 | { 153 | iBUFF0 = FX1Spacket->DATA_ARRAY[i]; 154 | sBUFF0 = "0000" + String(iBUFF0, HEX); 155 | sBUFF0.toUpperCase(); 156 | iBUFF1 = sBUFF0.length()-4; 157 | sBUFF2 = sBUFF0.substring(iBUFF1); 158 | 159 | msgframe[index] = sBUFF2[2]; 160 | index++; 161 | msgframe[index] = sBUFF2[3]; 162 | index++; 163 | msgframe[index] = sBUFF2[0]; 164 | index++; 165 | msgframe[index] = sBUFF2[1]; 166 | index++; 167 | } 168 | 169 | msgframe[index] = ETX; 170 | 171 | unsigned int iCheckSum = 0; 172 | for (unsigned char i = 1; i <= index; i++) 173 | iCheckSum += msgframe[i]; 174 | 175 | iBUFF0 = iCheckSum; 176 | sBUFF0 = "00" + String(iBUFF0, HEX); 177 | sBUFF0.toUpperCase(); 178 | iBUFF1 = sBUFF0.length()-2; 179 | sBUFF2 = sBUFF0.substring(iBUFF1); 180 | 181 | index++; 182 | msgframe[index] = sBUFF2[0]; 183 | index++; 184 | msgframe[index] = sBUFF2[1]; 185 | index++; 186 | 187 | return index; 188 | } 189 | 190 | unsigned char construct_FX1S_READ_D() 191 | { 192 | unsigned char index = 8; 193 | msgframe[index] = ETX; 194 | 195 | unsigned int iCheckSum = 0; 196 | for (unsigned char i = 1; i <= index; i++) 197 | iCheckSum += msgframe[i]; 198 | 199 | iBUFF0 = iCheckSum; 200 | sBUFF0 = "00" + String(iBUFF0, HEX); 201 | sBUFF0.toUpperCase(); 202 | iBUFF1 = sBUFF0.length()-2; 203 | sBUFF2 = sBUFF0.substring(iBUFF1); 204 | 205 | index++; 206 | msgframe[index] = sBUFF2[0]; 207 | index++; 208 | msgframe[index] = sBUFF2[1]; 209 | index++; 210 | 211 | return index; 212 | } 213 | 214 | 215 | void FX1Swaiting_for_reply() 216 | { 217 | 218 | if ((*FX1SPort).available()) // is there something to check? 219 | { 220 | unsigned char overflowFlag = 0; 221 | msgbuffer = 0; 222 | while ((*FX1SPort).available()) 223 | { 224 | 225 | if (overflowFlag) 226 | (*FX1SPort).read(); 227 | else 228 | { 229 | if (msgbuffer == FX1S_BUFFER_SIZE) 230 | overflowFlag = 1; 231 | 232 | msgframe[msgbuffer] = ASCII_Normalize((*FX1SPort).read()); 233 | msgbuffer++; 234 | } 235 | 236 | delayMicroseconds(FX1S_T1); // inter character time out 237 | } 238 | 239 | if (overflowFlag){ 240 | FX1SprocessError(); 241 | }else if (msgframe[0] == STX || msgframe[0] == ACK){ 242 | FX1SprocessReply(); 243 | }else{ 244 | FX1SprocessError(); 245 | } 246 | 247 | } 248 | else if ((millis() - FX1SdelayStart) > FX1Stimeout) // check FX1Stimeout 249 | { 250 | FX1SprocessError(); 251 | } 252 | } 253 | 254 | void FX1SprocessReply() 255 | { 256 | if(FX1S_ENQ_PROC){ 257 | if (msgframe[0]==ACK){ 258 | FX1Sstate = FX1S_IDLE; 259 | FX1S_ENQ_PROC = false; 260 | }else{ 261 | FX1Sstate = FX1S_ENQ; 262 | FX1S_ENQ_PROC = true; 263 | } 264 | }else{ 265 | switch (FX1Spacket->FNC) 266 | { 267 | case FX1S_WRITE_D: 268 | process_FX1S_WRITE_D(); 269 | break; 270 | case FX1S_READ_D: 271 | process_FX1S_READ_D(); 272 | break; 273 | default: 274 | FX1SprocessError(); 275 | break; 276 | } 277 | } 278 | } 279 | 280 | void process_FX1S_WRITE_D() 281 | { 282 | if (msgframe[0]==ACK){ 283 | FX1SprocessSuccess(); 284 | }else{ 285 | FX1SprocessError(); 286 | } 287 | } 288 | 289 | void process_FX1S_READ_D() 290 | { 291 | unsigned int TotalDataRead = (FX1Spacket->SIZE * 4) + 4; 292 | 293 | if (msgframe[0]==STX && TotalDataRead==msgbuffer) 294 | { 295 | unsigned long Sum = 0; 296 | for (unsigned char i = 1; i < msgbuffer-2; i++) 297 | Sum +=msgframe[i]; 298 | 299 | sBUFF0 = "00" + String(Sum, HEX); 300 | sBUFF0.toUpperCase(); 301 | iBUFF1 = sBUFF0.length()-2; 302 | sBUFF2 = sBUFF0.substring(iBUFF1); 303 | 304 | if(msgframe[msgbuffer-2] == sBUFF2[0] && msgframe[msgbuffer-1] == sBUFF2[1]){ 305 | unsigned int index = 1; 306 | for (unsigned char i = 0; i < FX1Spacket->SIZE; i++) 307 | { 308 | iBUFF0 = HexCharByte(msgframe[index+2]) * pow(16,3); 309 | iBUFF0 += HexCharByte(msgframe[index+3]) * pow(16,2); 310 | iBUFF0 += HexCharByte(msgframe[index]) * pow(16,1); 311 | iBUFF0 += HexCharByte(msgframe[index+1]) * pow(16,0); 312 | FX1Spacket->DATA_ARRAY[i] = iBUFF0; 313 | index += 4; 314 | } 315 | 316 | FX1SprocessSuccess(); 317 | }else{ 318 | 319 | FX1SprocessError(); 320 | } 321 | }else{ 322 | 323 | FX1SprocessError(); 324 | } 325 | } 326 | 327 | 328 | byte HexCharByte(unsigned char HexChar) 329 | { 330 | byte HexChar2byte = 0; 331 | if(HexChar==0x30)HexChar2byte=0x00; 332 | if(HexChar==0x31)HexChar2byte=0x01; 333 | if(HexChar==0x32)HexChar2byte=0x02; 334 | if(HexChar==0x33)HexChar2byte=0x03; 335 | if(HexChar==0x34)HexChar2byte=0x04; 336 | if(HexChar==0x35)HexChar2byte=0x05; 337 | if(HexChar==0x36)HexChar2byte=0x06; 338 | if(HexChar==0x37)HexChar2byte=0x07; 339 | if(HexChar==0x38)HexChar2byte=0x08; 340 | if(HexChar==0x39)HexChar2byte=0x09; 341 | if(HexChar==0x41)HexChar2byte=0x0A; 342 | if(HexChar==0x42)HexChar2byte=0x0B; 343 | if(HexChar==0x43)HexChar2byte=0x0C; 344 | if(HexChar==0x44)HexChar2byte=0x0D; 345 | if(HexChar==0x45)HexChar2byte=0x0E; 346 | if(HexChar==0x46)HexChar2byte=0x0F; 347 | return HexChar2byte; 348 | } 349 | 350 | 351 | void FX1SprocessError() 352 | { 353 | FX1Spacket->FX1Serror=1; 354 | FX1Spacket->FX1Sfailed_requests++; 355 | FX1Sstate = FX1S_ENQ; 356 | FX1SdelayStart = millis(); // start the turnaround delay 357 | } 358 | 359 | void FX1SprocessSuccess() 360 | { 361 | FX1Spacket->FX1Serror=0; 362 | FX1Spacket->FX1Ssuccessful_requests++; // transaction sent successfully 363 | FX1Sstate = FX1S_IDLE; 364 | FX1SdelayStart = millis(); // start the turnaround delay 365 | } 366 | 367 | void FX1S_configure(HardwareSerial* SerialPort, 368 | long FX1Sbaud, 369 | unsigned char FX1SbyteFormat, 370 | unsigned int _FX1Stimeout, 371 | FX1SPacket* _FX1Spackets, 372 | unsigned int _FX1Stotal_no_of_packets) 373 | { 374 | 375 | if (FX1Sbaud > 19200) 376 | FX1S_T1 = 750; 377 | else 378 | FX1S_T1 = 16500000/FX1Sbaud; // 1T * 1.5 = T1.5 379 | 380 | // initialize 381 | FX1Sstate = FX1S_ENQ; 382 | FX1Stimeout = _FX1Stimeout; 383 | FX1S_total_no_of_packets = _FX1Stotal_no_of_packets; 384 | FX1SpacketArray = _FX1Spackets; 385 | 386 | FX1SPort = SerialPort; 387 | (*FX1SPort).begin(FX1Sbaud, FX1SbyteFormat); 388 | 389 | } 390 | 391 | void FX1S_construct(FX1SPacket *_FX1Spacket, 392 | unsigned char FNC, 393 | unsigned int ADDR, 394 | unsigned int SIZE, 395 | unsigned int* DATA_ARRAY) 396 | { 397 | _FX1Spacket->FNC = FNC; 398 | _FX1Spacket->ADDR = ADDR; 399 | _FX1Spacket->SIZE = SIZE; 400 | _FX1Spacket->DATA_ARRAY = DATA_ARRAY; 401 | _FX1Spacket->FX1Sconnection = 1; 402 | } 403 | 404 | void FX1SsendPacket(unsigned char bufferSize) 405 | { 406 | for (unsigned char i = 0; i < bufferSize; i++) 407 | (*FX1SPort).write(msgframe[i]); 408 | 409 | 410 | (*FX1SPort).flush(); 411 | 412 | FX1SdelayStart = millis(); // start the FX1Stimeout delay 413 | } 414 | 415 | unsigned char ASCII_Normalize(unsigned char ASCII_Val) 416 | { 417 | unsigned char ASCII_Normal = 0; 418 | switch (ASCII_Val) 419 | { 420 | case 0x082: 421 | ASCII_Normal = 0x02; 422 | break; 423 | case 0x0B1: 424 | ASCII_Normal = 0x031; 425 | break; 426 | case 0x0B2: 427 | ASCII_Normal = 0x032; 428 | break; 429 | case 0x0B4: 430 | ASCII_Normal = 0x034; 431 | break; 432 | case 0x0B7: 433 | ASCII_Normal = 0x037; 434 | break; 435 | case 0x0B8: 436 | ASCII_Normal = 0x038; 437 | break; 438 | case 0x0C3: 439 | ASCII_Normal = 0x043; 440 | break; 441 | case 0x0C5: 442 | ASCII_Normal = 0x045; 443 | break; 444 | case 0x0C6: 445 | ASCII_Normal = 0x046; 446 | break; 447 | default: 448 | ASCII_Normal = ASCII_Val; 449 | break; 450 | } 451 | 452 | return ASCII_Normal; 453 | } 454 | -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/FX1S.h: -------------------------------------------------------------------------------- 1 | #ifndef FX1S_H 2 | #define FX1S_H 3 | 4 | #include "Arduino.h" 5 | 6 | #define FX1S_READ_D 0x30 7 | #define FX1S_WRITE_D 0x31 8 | 9 | #define ACK 0x06 10 | #define ENQ 0x05 11 | #define STX 0x02 12 | #define ETX 0x03 13 | 14 | typedef struct 15 | { 16 | unsigned char FNC; 17 | unsigned int ADDR; 18 | unsigned int SIZE; 19 | unsigned int* DATA_ARRAY; 20 | 21 | // FX1S information counters 22 | unsigned int FX1Srequests; 23 | unsigned int FX1Ssuccessful_requests; 24 | unsigned int FX1Sfailed_requests; 25 | unsigned int FX1Serror; 26 | 27 | // FX1Sconnection status of FX1Spacket 28 | unsigned char FX1Sconnection; 29 | 30 | }FX1SPacket; 31 | 32 | typedef FX1SPacket* FX1SpacketPointer; 33 | 34 | 35 | void FX1S_update(); 36 | 37 | void FX1S_construct(FX1SPacket *_FX1Spacket, 38 | unsigned char FNC, 39 | unsigned int ADDR, 40 | unsigned int SIZE, 41 | unsigned int* DATA_ARRAY); 42 | 43 | void FX1S_configure(HardwareSerial* SerialPort, 44 | long FX1Sbaud, 45 | unsigned char FX1SbyteFormat, 46 | unsigned int _FX1Stimeout, 47 | FX1SPacket* _FX1Spackets, 48 | unsigned int _FX1Stotal_no_of_packets); 49 | 50 | #endif -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/README.txt: -------------------------------------------------------------------------------- 1 | this program writen by Cartiman for program-plc.blogspot.com 2 | No sell and No Complaint -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/examples/Mitsubishi_PLC_FX1S/Mitsubishi_PLC_FX1S.ino: -------------------------------------------------------------------------------- 1 | #include 2 | //by program-plc.blogspot.com 3 | #define FX1Sbaud 19200 4 | #define FX1Sformat SERIAL_8N1 5 | #define FX1Stimeout 1000 6 | 7 | 8 | enum 9 | { 10 | FX1SPACKET1, 11 | FX1SPACKET2, 12 | FX1STOTAL_NO_OF_PACKETS 13 | }; 14 | FX1SPacket FX1Spackets[FX1STOTAL_NO_OF_PACKETS]; 15 | 16 | FX1SpacketPointer FX1Spacket1 = &FX1Spackets[FX1SPACKET1]; 17 | FX1SpacketPointer FX1Spacket2 = &FX1Spackets[FX1SPACKET2]; 18 | 19 | unsigned int FX1SreadD[1]; 20 | 21 | unsigned int FX1SwriteD[1]; 22 | 23 | #define AnalogInputPin A0 24 | #define AnalogOutputPin 9 25 | 26 | 27 | void setup() { 28 | 29 | FX1S_construct(FX1Spacket1, FX1S_READ_D, 0, 1, FX1SreadD); 30 | 31 | FX1S_construct(FX1Spacket2, FX1S_WRITE_D, 1, 1, FX1SwriteD); 32 | 33 | FX1S_configure(&Serial, FX1Sbaud, FX1Sformat, FX1Stimeout, FX1Spackets, FX1STOTAL_NO_OF_PACKETS); 34 | 35 | } 36 | 37 | 38 | void loop() { 39 | FX1S_update(); 40 | 41 | //Write to D1 42 | int sensorValue = analogRead(AnalogInputPin); 43 | int outputValue = map(sensorValue, 0, 1023, 0, 32767); 44 | FX1SwriteD[0] = outputValue; 45 | 46 | //Read from D0 47 | unsigned int D0 = FX1SreadD[0]; 48 | D0 = map(D0, 0, 32767, 0, 255); 49 | analogWrite(AnalogOutputPin, D0); 50 | 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/keywords.txt: -------------------------------------------------------------------------------- 1 | FX1SPacket KEYWORD1 2 | FX1SpacketPointer KEYWORD1 3 | FX1S_construct KEYWORD2 4 | FX1S_configure KEYWORD2 5 | FX1S_update KEYWORD2 6 | 7 | ###### Constants ###### 8 | FX1S_READ_D LITERAL1 9 | FX1S_WRITE_D LITERAL1 10 | -------------------------------------------------------------------------------- /Mitsubishi_PLC_FX1S_lib/library.properties: -------------------------------------------------------------------------------- 1 | name=Mitsubishi PLC FX1S librarie 2 | version=1.0.0 3 | author=Cartiman 4 | maintainer= 5 | sentence=This program writen by Cartiman for program-plc.blogspot.com. 6 | paragraph=This program writen by Cartiman for program-plc.blogspot.com. 7 | category=Other 8 | url=program-plc.blogspot.com 9 | architectures=* 10 | --------------------------------------------------------------------------------