NORDAC SK 400E
3.7 Programme de communication d'un PC:
Ce qui suit est un exemple simple de comment écrire un programme de communication
en mode Modbus ASCII à partir d'un PC en langage C.
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<process.h>
#define PORT 0x03F8 /* the address of COM1 */
/* the address offset value relative to COM1 */
#define THR 0x0000
#define RDR 0x0000
#define BRDL 0x0000
#define IER 0x0001
#define BRDH 0x0001
#define LCR 0x0003
#define MCR 0x0004
#define LSR 0x0005
#define MSR 0x0006
unsigned char rdat[60];
/* read 2 data from address 2102H of AC drive with address 1 */
unsigned char tdat[60]={':','0','1','0','3','2','1','0','2',
void main(){
int i;
outportb(PORT+MCR,0x08);
outportb(PORT+IER,0x01);
outportb(PORT+LCR,(inportb(PORT+LCR) | 0x80));
/* the BRDL/BRDH can be access as LCR.b7==1 */
outportb(PORT+BRDL,12);
12=115200/9600*/
outportb(PORT+BRDH,0x00);
outportb(PORT+LCR,0x06);
'0','0','0','2','D','7','\r','\n'};
/* interrupt enable */
/* interrupt as data in */
/* set baudrate=9600,
/* set protocol, <7,N,2>=06H
5-52
Notice de mise en service