Red de conocimiento informático - Problemas con los teléfonos móviles - Producción de código fuente Rtu

Producción de código fuente Rtu

Vea a continuación, espero que ayude.

//Nombre de archivo: RS232_x.C -

//Motivo: Se utiliza para la conexión RS232 entre VIGOR PLC modbus y el software de control de gráficos de PC.

//Instrucciones de uso:

//

/*

01: Leer estado de la bobina

02: Leer estado de entrada

03: Leer registro de retención

04: Leer registro de entrada

05: Forzar bobina simple

06: Registro único preestablecido

15: Forzar múltiples bobinas

16: Registros múltiples preestablecidos

22: Registro de escritura de máscara

23: Lectura/ escribir registro

*/

#pragma opción w32

#Contiene "msvcrt.h -"

#Incluye "windows.h -"

#Include "wingdi.h -"

//2006/65438

#Include "winbase.h -" "

#Incluye "winerror.h -"

#Incluye "advapi.h -"

#Incluye "winuser.h -"

#Número de definición 50

#Definición número_1 número+1

#Definición PI 3.141592654

#Definición ID_TIMER 1

Byte Text= "Bienvenido al Programa de prueba RS232 MODBUS 2006/10/19";

//Es mejor elegir un nombre que sea fácil de recordar y evitar el uso de A, B y C como nombres.

WNDCLASS wc

//WNDCLASSEX WC;

HWND hwnd

DCB dcb//Hong Kong el 29 de septiembre de 2006

p>

// Las variables que comienzan con p minúscula son en su mayoría funciones de puntero.

//El número de estación es 1, Y0, Y0 está activado.

byte spd[8]={1, 5, 0, 0, 255, 0, 140, 58}; //1, 5, 0, 0, ff, 0, 8c, 3a

//El número de estación es 1, Y0, Y0 está configurado en APAGADO.

byte spdx[8]={1, 5, 0, 0, 0, 0, 205, 202}; //1, 5, 0, 0, 0, 0, cd, ca

Byte ABCD[8];

MSG MSG;

HDC hdc

HMENU hMenu

Procesando hFile

p>

void main()

{

/*

WC tamaño = sizeof(WNDCLASSEX); línea, RegisterClassEx no verá la ventana.

*/

WC . h instancia = hth isinst;

WC lpsz nombre de clase = " Hola "; lpfnWndProc = # WndProc

WC .estilo = CS _ HREDRAW | CS _ VREDRAW

WC . hCursor = LoadCursor(0, IDC _ CROSS);

registrar clase(# WC);

hwnd=CreateWindowEx(0, "Hola", #Texto, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

0, 0, hThisInst, 0);

SetTimer (hwnd, ID_TIMER, 1000, NULL);

hFile=CreateFile("Com4 ",

Generic_READ | Generic_WRITE,

0,

Vacío,

open_existing,

file_attribute_normal,

0);

if(hfile = = invalid_handle_value)/ /Determine si COM se abrió correctamente.

{

MessageBox(0, "¡¡Error al abrir el puerto!!", "Error de comunicación", MB_OK

Return

}

//Pase la dirección dcb para abrir los parámetros de secuencia.

GetCommState(hFile, #dcb); //Conoce el estado actual de COM

dcb. abalat = 19200; //Establece la tasa de abulón en 19200.

dcb. ByteSize = 8; // bytes de 8 bits

dcb. Paridad = NOPARIDAD // La paridad es Ninguna.

dcb.

StopBits = ONESTOPBIT//Stop bits=1

//Establecer puerto

if (!SetCommState(hFile, #dcb))

{

MessageBox(0, "¡¡¡Error de configuración del puerto serie!!!", "Error de configuración", MB_OK);

cerrar identificador(hFile);

Regresar;

p>

}

ShowWindow(hwnd, 1);

mientras (GetMessage(#msg, 0, 0, 0))

Mensaje de programación (# msg);

}

Punto pt[50];

Wndproc largo (hwnd hwnd, uintmsg, wparam wparam, lparam lparam )//Función de ventana

{

static int cxClient, cyClient

punto estático pt[NUM_1];

static BOOL fFlipFlop = FALSE

HBRUSH hBrush

int I;

Float f;

PAINTSTRUCT ps

RECT rectángulo;

Cambiar (mensaje)

{

Caso WM_TIMER:

! fFlipFlop

invalidar estrupter(hwnd, NULL, FALSE);

if(fFlipFlop)

WriteFile(hFile, #spd, 8, #abcd, NULL) ;

Otro

WriteFile(hFile, #spdx, 8, #abcd, NULL);

Devuelve 0;

Caso WM_SIZE :

Cliente CX = LOWORD(lparam);

cyClient = hola palabra(lparam);

Rotura;

Caso WM_PAINT:

hdc = BeginPaint (hwnd, # PS);

GetClientRect (hwnd, # rect

if(fFlipFlop)

{

HB rush = CreateSolidBrush(RGB(255, 0, 0));

FillRect (hdc, #rect, hBrush

DrawText (hdc); , "El número de estación es 1, Y0 está activado", 16, #rect,

DT _ línea única | /p >

Otro

{

hBrush = CreateSolidBrush (RGB(0, 255, 0));

FillRect (hdc, #rect, hBrush) ;

DrawText (hdc, "El número de estación es 1, Y0 está configurado en APAGADO", 17, #rect,

DT _ línea única | DT _ CENTER | DT _ VCENTER);

}

MoveToEx (hdc, 0, cyClient/2, NULL);

LineTo(hdc, cxClient, cyClient/2); /p>

for(I = 0;i<=NUMi++)

{

pt[

i]. x = I * Cliente CX/NUM;

f = sin(PI * 2/NUM * I);

pt[i]. y = float 1-f * cyClient/2;

}

Polyline(hdc, #pt, NUM_1);

EndPaint (hwnd, # PS) ; //¡Esta línea es incorrecta! Puedes saberlo cambiando el nombre de la variable

eliminar objeto(HB rush);

romper;

Caso WM_DESTROY:

KillTimer (hwnd, ID_TIMER);

PostQuitMessage(0

Break

}

Devolver DefWindowProc(hwnd, msg, wparam, lparam);

}