-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLC_MITSU.h
106 lines (91 loc) · 4.13 KB
/
PLC_MITSU.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* PLC_MITSU.h
*
* Created on: Nov 2, 2018
* Author: Itachi
*/
#ifndef PLC_MITSU_H_
#define PLC_MITSU_H_
/*--------------------------\\//------------------------------- */
/*-------------------------Define value------------------------*/
#define RX1_PIN GPIO_PIN_0
#define TX1_PIN GPIO_PIN_1
#define STX 2 //Start of TeXt
#define ETX 3 //End of TeXt
#define M_MEM_READ 0x00 //From Autobase
#define M_SET 0x07 //From Autobase
#define M_RESET 0x08 //From Autobase
#define D_MEM_READ 0x01 //From Autobase
#define D_MEM_WRITE 0x11 //From Autobase
/*---------------------Assign variables------------------------*/
static char data_recv[15]={0};
static char data_send_2plc[15];
/* ---------Write_D(uint16_t Start_addr, uint16_t Value)---------
* Operating: Write D memory of PLC FX series
* write to D address (word-2 bytes)
* Data frame structure collect from Autobase
* Input: uint16_t Start_add(Address want to write), uint16_t Value(value to write)
* Output: None
* Write D address is 0x11
----------------------------------------------------------------*/
void Write_D(uint16_t Start_addr, uint16_t Value);
/* ------------Write_M(uint16_t Start_addr, uint8_t Type)------
* Operating: Write M memory of PLC FX series
* write to M address (Start_addr) (bit)
* Data frame structure collect from Autobase
* Input: uint16_t Start_add(Address want to write), uint8_t can be either SET or RESET
* Output: None
* Write M address is 0x0800
---------------------------------------------------------------*/
void Write_M(uint16_t Start_addr, uint8_t Type);
/* --------------Read_D(uint16_t Start_addr)--------------------
* Operating: Read D memory of PLC FX series
* Read from D address (Start_addr)
* up to D1023 (maximum)
* Data frame structure collect from Autobase
* Input: Start address (Address want to read)
* Output: Data value at Start_addr (uint16)
---------------------------------------------------------------*/
uint16_t Read_D(uint16_t Start_addr);
/* ------------------Read_M(uint16_t Start_addr)----------------
* Operating: Read M memory of PLC FX series
* Read from address (Start_addr) (bit)
* Data frame structure collect from Autobase
* Input: Start address (Address want to read)
* Output: Data value at Start_addr (bool)
---------------------------------------------------------------*/
bool Read_M(uint16_t Start_addr);
uint16_t ProcessData(uint8_t Mem_Type);
/* ----Calculate_Data(char byte0,char byte1,char byte2,char byte3)---
* Operating: Convert data receive from PLC to real value
* Input: Byte 0,1,2,3 of real data
* Output: 16-bit Real data
--------------------------------------------------------------------*/
uint16_t Calculate_Data(char byte0,char byte1,char byte2,char byte3);
/* ----------Convert_2Numb(char char_in)-----------------
* Operating: Convert character to number
* Input: character want to convert to number
* Output: corresponding number
* '0' - '9' -> 0 - 9
* 'A' - 'F' -> 0x0A - 0x0F
-------------------------------------------------------*/
uint8_t Convert_2Numb(char char_in); //convert char to uint8
/* ---------Convert_2Char(uint8_t numb_in)--------------
* Operating: Convert number to character
* Input: Number want to convert to char
* Output: corresponding char character
* 0 - 9 -> '0' -> '9'
* 0x0A ->0x0F return 'A'->'F'
-------------------------------------------------------*/
char Convert_2Char(uint8_t numb_in);//convert uint8 to char
/* ---------uint16_t Correct_Process(void)--------------
* Operating: Find the true value of Process function
* Because Process usually return 0, try (n=200) time if none zero return
* After 200 time but there no data except 0-> real data =0 return 0
* Input: NO
* Output: True value
* Change: Change the time n to test, n bigger test more time
* -> Increase accuracy but take more time to execute
-------------------------------------------------------*/
uint16_t Correct_Process(uint16_t Mem_type);
#endif /* PLC_MITSU_H_ */