Hello, very good and delighted to be with you again.
I am making a program in which I use RS485 communication with a transmission Enable Pin. To Transmit I need to activate the pin and once the transmission is finished I have to deactivate the pin to go into reception mode. Reviewing the transmission, I observe that I need approximately 2 milliseconds to send two bytes to 9600, so it occurred to me to use the CallSubPlus instruction with the following code.
Thank you so much
I am making a program in which I use RS485 communication with a transmission Enable Pin. To Transmit I need to activate the pin and once the transmission is finished I have to deactivate the pin to go into reception mode. Reviewing the transmission, I observe that I need approximately 2 milliseconds to send two bytes to 9600, so it occurred to me to use the CallSubPlus instruction with the following code.
This is the error that is generated. Any idea what might be going on?' ENCODER
'
' COMUNICACION PUERTO SERIE 1. ENCODER
'
' TX1--------> GPIO01
' RX1--------> GPIO03
' EN_TX1-----> GPIO27
'
' Solicitud de Informacion -> A2 B0 o A2 B3 segun sentido de giro de la puerta.
' Respuesta de la puerta 3 BYTE, B0 = 163 = Datos Correctos, B1*256 + B2 = Posicion
'
' Transmitir dos BYTE a 9600 tarda Aproximadamente 1,9ms
'
Sub Process_Globals
Public ms_Lee_Encoder As Byte = 10 ' ms entre lecturas del Encoder
Private Sentido_Encoder As Boolean = True ' Sube Puerta, Sube Valor, si Sube puerta y baja Balor = False
Private T_Encoder As Timer ' Temporizador Llamadas de Lectura del Encoder
Private En_Tx_Encoder As Pin ' Pin de Habilitacion Transmision del Encoder
Public Serial1 As Serial ' Puerto Serie 1 (USb y Encoder)
Private PS1 As AsyncStreams ' Entrada de Datos del Puerto Seria
Private bc As ByteConverter
Public Error_C_Encoder As ULong ' Errores de Comunicacion con el Encoder
Public NC_T_Encoder As ULong ' Numero de Comunicaciones Enitidas al Encoder
Public NC_R_Encoder As ULong ' Numero de Comunicaciones Recividas del Encoder
End Sub
public Sub Inicializa_Encoder
' Inicializa la Velocidad del Puerto Serie 1
Serial1.Initialize(9600)
' Pin de Habilitacion de Transmision
En_Tx_Encoder.Initialize(27,En_Tx_Encoder.MODE_OUTPUT)
' Fuerza a CERO el Pinde Transmision
En_Tx_Encoder.DigitalWrite (False)
' Inicializa el Puerto Serie 1
PS1.Initialize(Serial1.Stream, "PS1_newdata","PS1_Error")
' Lanza Lectura del Encoder
T_Encoder.Initialize("PS1_Tick",ms_Lee_Encoder)
T_Encoder.Enabled = True
End Sub
'
' Rutina de Peticion de Datos del Encoder
'
' Peticion en sentido Descendente A0,B0 (A0 = 160, B0 = 176)
' Peticion en Sentido Ascendente A0,B3 (A0 = 160, B3 = 179)
'
Private Sub PS1_Tick
Dim B(2) As Byte
' Segun el Sentido de la Puerta
If Sentido_Encoder = True Then
B(0) = 160 ' A0
B(1) = 176 ' B0
Else
B(0) = 160 ' A0
B(1) = 179 ' B3
End If
' Activa Transmision.
En_Tx_Encoder.DigitalWrite(True)
' Envia los Datos
PS1.Write(B)
' DesActiva Transmision en 2ms
CallSubPlus("EN_TX1_Off",2,0)
End Sub
' Entrada de Datros del Puerto Serie
Private Sub PS1_newdata (Buffer() As Byte)
Log("Encoder " , bc.StringFromBytes(Buffer), " ", Buffer.Length) '
End Sub
' Errores de Comunicacion con el Encoder
private Sub PS1_Error
Error_C_Encoder = Error_C_Encoder +1
End Sub
private Sub Revisa_Limites_Cnt
If Error_C_Encoder > 10000000 Then
End If
End Sub
'
' Desactiva la Transmision de TX1
'
Private Sub EN_TX1_Off
En_Tx_Encoder.DigitalWrite(False)
End Sub
Thank you so much