2 Attachment(s)
Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
I'm playing with and I XSCADA problem arose when finished ... program it does not work ... Usually use software-controlled communication, but in this case, as I wanted to meet other microcontroller functions, preferably do control communication hardware ... It's where I start my problem that did not work and I read several topics and I could not take it forward to the project ....
We split.
This is the program I wrote for a PIC16F877A
Code:
include "modedefs.bas"
define osc 4
ADCON1=000010
TRISA=255
TRISB=111111
TRISC=000000
OPTION_REG.7=0
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h ;"BRGH a 0 para 2400,-->20, para 9600 ponerlo a 24
DEFINE HSER_BAUD 9600 ;"Velocidad de transmision 9600
DEFINE LCD_DREG PORTD ;bit de datos del LCD empezando
DEFINE LCD_BITS 4 ;en modo 4 bits
DEFINE LCD_DBIT 4 ;por D.4, D.5, D.6 y D.7
DEFINE LCD_RSREG PORTD ;bit de registro del LCD conectar
DEFINE LCD_RSBIT 2 ;en el puerto D.2
DEFINE LCD_EREG PORTD;bit de Enable conectar en el
DEFINE LCD_EBIT 3 ;puerto D.3
DEFINE LCD_LINES 2
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
VOLT VAR WORD
MV VAR BYTE
MA VAR BYTE
HVD var word
AMPER var word
LECTURA VAR WORD
AUX_TX var byte ; NO SE USA
AUX_TX1 VAR BYTE ;PWM
AUX_TX2 VAR BYTE ;ADC
AUX_TX3a VAR BYTE ;ENTRADAS DIG
AUX_TX3b VAR BYTE ;ENTRADAS DIG
AUX_TX3c VAR BYTE ;ENTRADAS DIG
AUX_TX3d VAR BYTE ;ENTRADAS DIG
AUX_TX4 VAR BYTE ;SALIDAS DIG
AUX_TX5 VAR BYTE ;ESTADO PWM
AUX_RX var byte ; NO SE USA
AUX_RX1 VAR BYTE ; NO SE USA
AUX_RX2 VAR BYTE ; NO SE USA
AUX_RX3 VAR BYTE ; NO SE USA
AUX_RX4 VAR BYTE ;ORDEN DEL SCADA
tiempo var byte
bandera var byte
x var byte
nivel var byte
PORTD=0
VOLT=0
PAUSE 100
LCDOUT $FE,1
arranque:
;INTCON = 000000 ' Habilita interrupciones
INTCON.7 = 0 'apago interrupciones generales
INTCON.6 = 0 'idem con perifericas
INTCON.5 = 0 'idem con Int de TMR0
ON INTERRUPT GoTo serialin ' Ante interrupcion ir a "serialin"
;PIE1.5 = 1 ' Habilita interrupciones por USART
PIE1 = 110000 'Enable interrupts
nivel = 0
INICIO:
If PIR1.5 = 1 Then Goto serialin
;HSerIn [Dec AUX_RX]
IF portc.4 = 0 THEN gosub sumarPWM1
IF portc.5 = 0 THEN gosub restarPWM1
IF portb.1 = 0 then
AUX_TX3a = 11
else
AUX_TX3a = 10
endif
if portb.2 = 0 then
AUX_TX3b =21
else
AUX_TX3b =20
endif
if portb.3 = 0 then
AUX_TX3c =31
else
AUX_TX3c =30
endif
if portb.4 = 0 then
AUX_TX3d =41
else
AUX_TX3d =40
endif
IF ADCON0.2= 1 THEN INICIO
gosub lectura_ADC
LCDOUT $FE,1
LCDOUT $FE,$02,"V=",DEC VOLT,",",DEC1 MV," A=",DEC2 AMPER,",",DEC2 MA
LCDOUT $FE,$C0,"pwm=",DEC tiempo
AUX_TX5 = NIVEL
AUX_TX4 = PORTD
AUX_TX2 = AMPER
AUX_TX1 = VOLT
PWM PORTC.2,nivel,100
pause 5
HSEROUt ["[1;1;W;",dec AUX_TX1,13] ;envio adc volts
HSEROUt ["1;1;W;",dec AUX_TX1,13] ;envio adc volts
pause 5
HSEROUt ["[","1","1","W",dec AUX_TX1,"]",13] ;envio adc volts
HSEROUt ["[1;2;W;",AUX_TX2,13] ;envio adc amp
pause 5
HSEROUt ["[1;3;W;",AUX_TX3a,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3b,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3c,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3d,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;4;W;",AUX_TX4,13] ;envio estado salidas digitales
pause 5
HSEROUt ["[1;5;W;",AUX_TX5,13] ;envio estado PWM
GOTO INICIO
lectura_ADC:
ADCIN 0,LECTURA
HVD=((LECTURA+1)*/875)/10
VOLT=HVD/10
MV=(HVD)//10
ADCIN 1,LECTURA
HVD=(LECTURA+1)*/250
AMPER=HVD/100
MA=HVD//100
return
sumarPWM1:
if nivel => 255 then return
nivel= nivel+5
return
restarPWM1:
if nivel => 1 then return
nivel = nivel - 1
return
DISABLE
serialin: ' Buffer the character received
PIE1 = 000000 'Disable interrupts
HSerIn [Dec AUX_RX, dec AUX_RX1, DEC AUX_RX2 , DEC AUX_RX3]
Select case AUX_RX3
case 1
toggle PORTC.0
case 2
TOGGLE PORTC.2
case 3
TOGGLE PORTC.3
case 4
TOGGLE PORTC.4
case 5
if nivel => 255 then INICIO
nivel= nivel+5
return
CASE 6
if nivel => 1 then INICIO
nivel = nivel - 1
return
END SELECT
PIE1 = 110000 'Enable interrupts
Resume
end
The editor of scada, can handle multiple communication protocols.
Ascii Protokol :
Send String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Write;Value]
Receive String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Read;Value]
In my case, configure the different entries in different variables (addresses) to control the functions ... For example, to control the analog voltmeter and ammeter, select the Address List 1 and 2 ($ 1 - $ 2) ...
I mean, from the pic would have to send
[1,1, W, adc value Volts] and [1,2, W, Amp adc value].
This same action, but with different addresses can complete them with the various functions of the software, but when run proteus and scada, and does not work in proteus rs-232 terminal, you see the error indicator ...
Attachment 7350 Attachment 7351
I help to find the problem that really do not understand?
No if I firewall blocks port ...
not if I am misusing HSERIN and HSEROUT ...
or, is some small error
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
This description
Quote:
I mean, from the pic would have to send
[1,1, W, adc value Volts] and [1,2, W, Amp adc value].
is not the same as code
Code:
HSEROUt ["[1;1;W;",dec AUX_TX1,13] ;envio adc volts
HSEROUt ["1;1;W;",dec AUX_TX1,13] ;envio adc volts
should be
HSEROUT [1,1,W,dec AUX_TX1,13] 'envio adc volts
I think?
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
SERIALIN interrupt subroutine has 1 RESUME and 2 RETURNs, not sure that will work as expected.
PBP interrupts are "special". Darrel's interrupt routines are much more reliable and easy to use.
Robert
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
hi thanks for replying ....
Quote:
Originally Posted by
EarlyBird2
This description
is not the same as code
Code:
HSEROUt ["[1;1;W;",dec AUX_TX1,13] ;envio adc volts
HSEROUt ["1;1;W;",dec AUX_TX1,13] ;envio adc volts
should be
HSEROUT [1,1,W,dec AUX_TX1,13] 'envio adc volts
I think?
changing those lines and did not work ... adding the probe in the "" W because that indicates if write or read and not have problems ... both to receive and send packets to the serial port ... .
with serine and serout probe to see if it was a problem that the port is blocked and apparently, that's another mistake more than I have in this example.
I'll investigate the issue of ports to get me doubt ...
Quote:
Originally Posted by
Demon
SERIALIN interrupt subroutine has 1 RESUME and 2 RETURNs, not sure that will work as expected.
PBP interrupts are "special". Darrel's interrupt routines are much more reliable and easy to use.
Robert
Robert, see, you could guide me in those breaks you mention?
sorry for my spanglish :D
3 Attachment(s)
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
Well! I found a problem and already almost solved ... this port is blocked, so use a virtual port for nesting
Attachment 7352
but now I see communication by the hyper terminal, note that there is a speed problem, so I do not recognize the package and data ... this is the catch:
Attachment 7353
test at a lower bauderate OR CHANGE PARITY? in this case as set HSERIN and HSEROUT to work at another speed? I think part of the problem here ... sure then continues with the theme of interruptions
settings was 8n1 9600 for both applications
Attachment 7354
1 Attachment(s)
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
:D ready .... one less problem ... I haven´t configured in the hyperterminal as reversed polarity
now continue with the rest to see and understand that the package is not interpretedAttachment 7355
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
I struck me ... I'm locked ... I get angry that I can not take this issue forward ... I turned round and round and do not understand where is the error ... Copy and paste them as examples to work and backed away more , what progress, because now I understand much less than before the function HSERIN / HSEROUT ...
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
Do you have a logic probe to see exactly what is transmitted?
Robert
Edit: http://www.picbasic.co.uk/forum/showthread.php?t=18952
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
Hello friend; It was first tested in a virtual version (Proteus + + Xscada Virtual Serial Port Driver).
Xscaa brings a tool to read the data packet that enters and exits the ports ... you can write to them too.
Just went up a video capture as I can write to the port to see ... now check the link you gave me to wake neurons also see ...
http://youtu.be/Rxm0gO_wWMM
Thanks for helping / bearings
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
A simulation can only detect what it is programmed to detect.
I'd love to afford one, but sometimes you have to build the real thing.
Robert
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
You're right; Tonight I will go to the board and I do physical tests ... take them it with serine and serout and once it achieves communication, shall pass to HSERIN / OUT ... I did not find any complete example in SanGoogle which guide me.
Tomorrow I commented as I was.
Re: Firewall win, or programmed wrong ... the problem is me? (HSERIN-PC)
I returned with news.
Well, we can say that there were many things which would not let me make the project.
On one hand, I had problems with the port of my PC, it crashes when more than one program wants to work with this.
On the other hand, although I could not make it work with HSERIN-OUT, accomplish it working with conventional serine and biggest mistake was in the way in which the variable sent ... In early attempts never included the "#". ..
Serout PORTC.6, T9600, ["[1,1, W,", # VOLT, "]"]
Another error in the first attempts, was the way in which the data expected. At first he was waiting at a specific point data and the program was obsolete (that is why I wanted to know how to use HSERIN-OUT, to do this to interrupt mode and keep the program running normal). The solution I found him, but only for short programs that do not have many instructions, is to use the following lines ...
SERIN PORTC.7,10,["[1,3,W,"],DATO
Interestingly, I can send a decimal variable and work it handles XSCADA to represent the analog graph.
Here's a simpler than video achieved so far, as you can understand HSERIN-OUT, an article for the community http://www.picbasic.co.uk in the section where my other two articles arme next:
http://www.picbasic.co.uk/forum/cont...=491-Sensor-02
http://www.picbasic.co.uk/forum/cont...9-en-Espa%F1ol
http://youtu.be/X3jeqzHoghc
sorry for my spanglish