Nel avatar del'altro forum sembra che povero suibaf sia invecchiato un po' , forse e' lo stress di questo progettino.attenzione che lì ti bacchettano
Config Pinc.0 = Output
Waitms 30 ' delay
Print #1 , Makemodbus(7 , 6 , 40000 , W); ' slave 2, function 6, address 40000 , value of w
Waitms 30
Print #1 , Makemodbus(7 , 6 , 40001 , W); ' slave 2, function 6, address 40001 , value of w
W = W+1
Print #3 , Makemodbus(7 , 6 , 100 , W);
Waitms 100
Print #3 , Makemodbus(7 , 6 , 102 , W);
Waitms 100
Per qualche ragione funziona benissimo con i miei boards e con 30ms di intervallo.così non va bene.
Ma almeno fai come i miei vecchi maestri e segnali in rosso...(editato deluca)
'-----------------------------------------------------------------------------------------
'rs485-modbus-master_2560.bas
'FS
'-------------------------------------------------------------------------------
$regfile = "m2560def.dat" ' used micro
$crystal = 16000000 ' used xtal
$hwstack = 40
$swstack = 40
$framesize = 40
'-------------------------------------------------------------------------------
$lib "modbus.lbx" ' specify the additional library
'the libray will call a routine for UAR0,UART1,UAR2 and/or UAR3.
'when you get an error message that a label is not found with _SENDCHAR3 or _SENDCHAR4 then add these labels
'when you later use these routines you might get a duplicate label error and then you need to remove them
Config Print2 = Portc.0 , Mode = Set 'porta seriale per Modbus
Config Pinc.0 = Output
Rs485dir Alias Portc.0 'make an alias
'set direction register to output
Rs485dir = 0 ' set the pin to 0 for listening
'configure the second UAR for RS485/MODBUS. Make sure all slaves/servers use the same settings
Config Com3 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'Configute the timer to use the clock divided by 1024
Config Timer0 = Timer , Prescale = 1024
'T = 256* precaler/fosc =256*1024/16000000 = 16,384 mS
'quindi sifnifica che ogni 16,384mS ci sarà un overflow
'Define the ISR handler (Interrupt Service Routine)
On Ovf0 Tim0_isr
'you may also use TIMER0 for OVF0, it is the same
Enable Timer0 ' enable the timer interrupt
Enable Interrupts
'use OPEN/CLOSE for using the second UART
Open "Com3:" For Binary As #3
'dimension some variables
Dim W As Word
Dim Contataore_send_plc As Byte
Dim 250ms As Byte
Dim Costante_plc As Byte
Dim Uid_card(4) As Byte
Costante_plc = &H0A
Uid_card(1) = &H1A
Uid_card(2) = &H2B
Uid_card(3) = &H3C
Uid_card(4) = &H4D
'Print "RS-485 MODBUS master"
Do
Loop
'///////////////////////INTERRUPT//////////////////////////////////////////////
'the following code is executed when the timer rolls over
'Qui faccio la rchiesta dei dati ogni 200ms
Tim0_isr:
Incr 250ms ' Spedizione dati al plc
If 250ms = 15 Then 'ogni poco piu' di 250 ms
Incr Contataore_send_plc
If Contataore_send_plc = 1 Then Print #3 , Makemodbus(2 , 6 , 100 , Uid_card(1));
If Contataore_send_plc = 2 Then Print #3 , Makemodbus(2 , 6 , 101 , Uid_card(3));
If Contataore_send_plc = 3 Then Print #3 , Makemodbus(2 , 6 , 110 , Costante_plc ); 'Costante per PLC
If Contataore_send_plc = 4 Then Contataore_send_plc = 0
250ms = 0
End If
Return
Close #3
_sendchar0:
_sendchar1:
_sendchar4:
End
For function 06 which can only write a single register, this can be a byte or integer or word.
If Contataore_send_plc = 4 Then Contataore_send_plc = 0
se=4 avrai sull'int handler del timer un dead-cycle.
Users browsing this forum: No registered users and 22 guests