hola sir viciony respondiando tarde pero seguro no havia podido tener tiempo para meterme en el foro.
respondiendo a tu pregunta si ocupo todos los protocolos con el mismo micro es cierto los 5 protocolos que en relidad son 4 mas rs-485. son todos im0plementados al mismo tiempo en el micro y la maqueta pero no te confundas todos no son utilizados al mismo tiempo cada uno sera implementado por separado para el entrenami8ento de los estudiantes.
bueno con respecto a la diferencia entre los protocolos RS-232 y RS-485 son grandes devido a que el protocolo de pic RS-232 es de tipo TTL y es convertido por como bien se sabe por un MAX232 o areglo de transistores a las tenciones originales del protocolo que van desde 12V a -12V ademas de esto la informacion es decir los unos y ceros en dicho protocolo estan referenciadas a tierra o GND en cambio en el protocolo RS-485 la informacion se envia y recive enla forma de tenciones diferenciales entre el par de hilos que utiliza el mismo protocolo (en el caso que no utilises señales de control).
con el protocolo RS-232 se alcansan distencias de 15 metros y con el RS-485 las distancias aumentan elo doble me imagino yo que es devido por la forma de envio de datos que es por tenciones diferenciales.
en cuanto a los niveles de voltaje en el RS-485 no estoy al tanto de esto seguro te lo averigua para ofrecerte la informacion completa ademas de esto tambien deves tener un integrado que te aga la traduccion de RS-232 a RS-485 el cual es el MAX487 o puedes encontrar otro que se adapte mas a la palicacio que estas realizando.
aqui esta el data sheet para que lo veas
http://www.datasheetcatalog.com/datasheets_pdf/M/A/X/4/MAX487.shtmlbueno ya que me afrecistes ayuda acerca del desarrollo con el puerto usb te muestro lo que tengo para la inplementacion:;
empecemos con lo de visual:
tengo dos modulos para el manejo del protocolo los consegui ase poco no se como funcionan te los muestro para ver que piensas acerca de ellos
uno es el HIDinterface:
*********************************************************************************************************
' This module is common to all of the Example programs
' It declares the {Open, Read, Write, Close} calls for the USB device
' These user-calls are translated into OS system calls
' This module also contains several support routines used by all of the examples
'
' Declare module-wide variables
Private HidHandle As Long
Public Function OpenUSBdevice(NameOfDevice$) As Boolean
' This function searches the system HID tables for NameOfDevice$
' If found then it opens the device and returns TRUE, else it returns FALSE
Dim HidGuid As Guid: Dim Success As Boolean: Dim Openned As Boolean: Dim Buffer(256) As Byte
Dim DeviceInterfaceData As Device_Interface_Data
Dim FunctionClassDeviceData As Device_Interface_Detail
'
' First, get the HID class identifier
Call HidD_GetHidGuid(HidGuid.Data(0))
' Get a handle for the Plug and Play node, request currently active HID devices
PnPHandle& = SetupDiGetClassDevs(HidGuid.Data(0), 0, 0, &H12)
If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")
'
HidEntry& = 0: Openned = False
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes
' Look through the table of HID devices
Do While SetupDiEnumDeviceInterfaces(PnPHandle&, 0, HidGuid.Data(0), HidEntry&, DeviceInterfaceData.cbsize)
' There is a device here, get it's name
FunctionClassDeviceData.cbsize = 5
Success = SetupDiGetDeviceInterfaceDetail(PnPHandle&, DeviceInterfaceData.cbsize, _
FunctionClassDeviceData.cbsize, UBound(FunctionClassDeviceData.DataPath), BytesReturned&, 0)
If (Success = 0) Then ErrorExit ("Could not get the name of this HID device")
' Convert returned C string to Visual Basic String
hidname$ = "": i& = 0
Do While FunctionClassDeviceData.DataPath(i&) <> 0
hidname$ = hidname$ & Chr$(FunctionClassDeviceData.DataPath(i&)): i& = i& + 1: Loop
' Can now open this HID device
Dim SA As Security_Attributes
HidHandle& = CreateFile(hidname$, &HC0000000, 3, SA, 3, 0, 0)
If (HidHandle = -1) Then ErrorExit ("Could not open HID device")
' Is it OUR HID device?
If HidD_GetProductString(HidHandle&, AddressFor(Buffer(0)), UBound(Buffer)) Then
DeviceName$ = "": i& = 0
Do While Buffer(i&) <> 0: DeviceName$ = DeviceName$ & Chr$(Buffer(i&)): i& = i& + 2: Loop
If (StrComp(DeviceName$, NameOfDevice$) = 0) Then
Openned = True: Exit Do: End If
End If 'HidD_GetProductString
Call CloseHandle(HidHandle&) ' Was not OUR HID device
HidEntry& = HidEntry& + 1 ' Check next entry
Loop 'SetupDiEnumDeviceInterfaces returns FALSE when there are no more entries
SetupDiDestroyDeviceInfoList (PnPHandle&)
OpenUSBdevice = Openned
End Function
Public Sub ReadUSBdevice(BufferPtr&, ByteCount&)
' This subroutine "reads" from an openned USB device
' This routine gets an Input Report from the USB device and returns the data
' NOTE that ReadFile is a BLOCKING system call, ie it will wait for the USB device to respond
' Do not configure the USB device to "Generate report only on change" since the program
' will appear to 'hang'
' Use a local buffer so that the ReportID (=0) at ReportBuffer(0) may be removed
Dim ReportBuffer(256) As Byte
If ByteCount& > 254 Then ErrorExit ("Maximum ByteCount for ReadUSBdevice is 254")
If ByteCount& < 1 Then ErrorExit ("Minimum ByteCount for ReadUSBdevice is 1")
Success = ReadFile(HidHandle&, AddressFor(ReportBuffer(0)), ByteCount& + 1, BytesReturned&, 0)
If (Success = 0) Then ErrorExit ("Could not get an Input Report")
Call CopyBuffer(AddressFor(ReportBuffer(1)), BufferPtr&, BytesReturned& - 1)
End Sub
Public Sub WriteUSBdevice(BufferPtr&, ByteCount&)
' This subroutine "writes" to an openned USB device
' Copy the user buffer into a local buffer so that a ReportID (=0) may be prepended
' The first byte will contain the ReportID (=0)
Dim ReportBuffer(256) As Byte
If ByteCount& > 254 Then ErrorExit ("Maximum ByteCount for WriteUSBdevice is 254")
Call CopyBuffer(BufferPtr&, AddressFor(ReportBuffer(1)), ByteCount&)
ReportBuffer(0) = 0 ' ReportID
Success = WriteFile(HidHandle&, AddressFor(ReportBuffer(0)), ByteCount& + 1, BytesWritten&, 0)
If (Success = 0) Then ErrorExit ("Could not write an Output Report")
End Sub
Public Sub CloseUSBdevice()
' This subroutine closes the USB device that we have been using
Call CloseHandle(HidHandle&)
End Sub
Public Function ReturnHexByte(Text$) As Byte
' Converts the first two characters of text$ into a byte
Dim Value As Byte
Utext$ = UCase(Text$) ' Convert to uppercase for search
HexString$ = "0123456789ABCDEF" ' Non-Hex characters = 0
Value = 0
For i& = 0 To 15
If Mid(Utext$, 1, 1) = Mid(HexString$, i& + 1, 1) Then Value = Value + (16 * i&)
If Mid(Utext$, 2, 1) = Mid(HexString$, i& + 1, 1) Then Value = Value + i&
Next i&
ReturnHexByte = Value
End Function
Public Function TwoHexCharacters$(Value As Byte)
HexString$ = "0123456789ABCDEF"
TwoHexCharacters$ = Mid(HexString$, Int(Value / 16) + 1, 1) & Mid(HexString$, Int(Value And &HF) + 1, 1)
End Function
Public Function TwoDecimalCharacters$(Value As Byte)
DecimalString$ = "0123456789"
Tens& = Int(Value / 10): Units& = Value - (10 * Tens&)
TwoDecimalCharacters$ = Mid(DecimalString$, Tens& + 1, 1) & Mid(DecimalString$, Units& + 1, 1)
End Function
Public Function ThreeDecimalCharacters$(Value As Byte)
h& = Int(Value / 100): t& = Int((Value - (100 * h&)) / 10): u& = Value - (100 * h&) - (10 * t&)
ThreeDecimalCharacters$ = h& & t& & u&
End Function
Public Sub ErrorExit(Reason$)
ErrorCode = GetLastError()
Call MsgBox(Reason$, vbCritical)
If ErrorCode <> 0 Then
Stop
End If
End Sub
*********************************************************************************************************
y el otro es el USBinterface
*********************************************************************************************************
'
' Declare all of the USB Data Structures
'
' Note that most of these Data Structures MUST be defined a BYTES.
' This prevents Visual Basic "helpfully" aligning variables on their natural byte boundaries.
' Little Endian is assumed. ie If Byte(3)= Long, Then byte(0) = LSB
'
Public Type UNameType: Length As Long: UnicodeName(256) As Byte: End Type
Public Type UNodeType: ConnectionIndex As Long: Length As Long: UnicodeName(256) As Byte: End Type
Public Type SetupPacket
RequestType As Byte: Request As Byte: wValueLo As Byte: wValueHi As Byte: wIndex As Integer: wLength As Integer: End Type
Public Type DescriptorRequest
ConnectionIndex As Long: PacketData As SetupPacket: ConfigurationDescriptor(2000) As Byte: End Type
Public Type DeviceDescriptor
Contents(17) As Byte: End Type
' Defined as a Byte Array to make later data movement simpler
' Length As Byte: DescriptorType As Byte: USBSpec(1) As Byte: Class As Byte
' SubClass As Byte: Protocol As Byte: MaxEP0Size As Byte: VendorID(1) As Byte
' ProductID(1) As Byte: DeviceRevision(1) As Byte: ManufacturerStringIndex As Byte
' ProductStringIndex As Byte: SerialNumberStringIndex As Byte: ConfigurationCount As Byte: End Type
Public Type HubDescriptor
Length As Byte: HubType As Byte: PortCount As Byte: Characteristics(1) As Byte
PowerOn2Good As Byte: MaxCurrent As Byte: PowerMask(63) As Byte: End Type
Public Type EndPointDescriptor
Length As Byte: DescriptorType As Byte: EndpointAddress As Byte
Attributes As Byte: MaxPacketSize(1) As Byte: PollingInterval As Byte: End Type
Public Type NodeInformation
NodeType As Long: NodeDescriptor As HubDescriptor: HubIsBusPowered As Byte: End Type
Public Type NodeConnectionInformation
ConnectionIndex As Long: ThisDevice As DeviceDescriptor: CurrentConfiguration As Byte
LowSpeed As Byte: DeviceIsHub As Byte: DeviceAddress(1) As Byte: NumberOfOpenEndPoints(3) As Byte
ThisConnectionStatus(3) As Byte: MyEndPoints(29) As EndPointDescriptor: End Type
' I keep all of the IO Device information I collect in a big table
' Most USB installations will only fill part of this table
Public Type CollectedDeviceData
DeviceType As Long: DeviceHandle As Long: ConnectionData As NodeConnectionInformation
NodeData As NodeInformation: End Type
Public DeviceData(200) As CollectedDeviceData
'
' All Descriptors are concatenated here once a device is selected
Public DescriptorData(2000) As Byte
'
' I need to send Requests to USB devices
Public PCHostRequest As DescriptorRequest
'
Public ConnectionStatus(6) As String
'
' Declare my support sub-routines
Public Function DataIndex()
' All writes to the DeviceData table are done to entry DataIndex
' Need to keep DeviceData and IODevice_Display in sync
DataIndex = Collect_Data.Device_Display.ListCount
End Function
Public Function OpenConnection(Name$)
Dim SA As Security_Attributes
Handle& = CreateFile("\\.\" & Name$, &HC0000000, 3, SA, 3, 0, 0)
If Handle& = 0 Then ErrorExit ("Could not open a connection to " & Name$)
OpenConnection = Handle&
End Function
Public Sub GetNodeInformation(Handle&)
' Get the node information
Dim BytesReturned&, Status&
Status& = DeviceIoControl(Handle&, &H220408, DeviceData(DataIndex).NodeData.NodeType, 256, DeviceData(DataIndex).NodeData.NodeType, 256, BytesReturned&, 0)
If Status& = 0 Then ErrorExit ("Could not get node information")
If BytesReturned& > 256 Then ErrorExit ("DeviceIOControl returned >256 bytes of data")
End Sub
Public Sub GetNodeConnectionData(Handle&, PortIndex&)
Dim BytesReturned&, Status&
DeviceData(DataIndex).ConnectionData.ConnectionIndex = PortIndex&
Status& = DeviceIoControl(Handle&, &H22040C, DeviceData(DataIndex).ConnectionData.ConnectionIndex, 256, DeviceData(DataIndex).ConnectionData.ConnectionIndex, 256, BytesReturned&, 0)
If Status& = 0 Then ErrorExit ("Could not get Node Connection Data")
If BytesReturned& > 256 Then ErrorExit ("DeviceIOControl returned >256 bytes of data")
End Sub
Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
Dim NameBuffer As UNameType
'
' First need to get the length of the name string
Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0, NameBuffer.Length, 260, BytesReturned&, 0)
If Status& = 0 Then ErrorExit ("Could not get LENGTH of " & DeviceName$ & " Name")
If NameBuffer.Length > 256 Then ErrorExit (Name$ & " Name > 256 Characters")
'
' . . . and then the string. It will be returned in UNICODE format
Status& = DeviceIoControl(DeviceHandle&, API_ID&, NameBuffer.Length, NameBuffer.Length, NameBuffer.Length, NameBuffer.Length, BytesReturned&, 0)
If Status& = 0 Then ErrorExit ("Could not get TEXT of " & DeviceName$ & " Name")
temp$ = "": i = 0 'A simple unicode to basic string conversion
Do While NameBuffer.UnicodeName(i) <> 0: temp$ = temp$ & Chr(NameBuffer.UnicodeName(i)): i = i + 2: Loop
GetNameOf$ = temp$ 'StrConv(NameBuffer.Length, vbFromUnicode)
End Function
Function GetExternalHubName$(ConnectionIndex&, DeviceHandle&)
Dim NameBuffer As UNodeType
'
' First need to get the length of the name string
NameBuffer.ConnectionIndex = ConnectionIndex
Status& = DeviceIoControl(DeviceHandle&, &H220414, NameBuffer.ConnectionIndex, 260, NameBuffer.ConnectionIndex, 260, BytesReturned&, CNull)
If Status& = 0 Then ErrorExit ("Could not get LENGTH of External Hub Name")
If NameBuffer.Length > 256 Then ErrorExit ("External Hub Name > 256 Characters")
'
' . . . and then the string. It will be returned in UNICODE format
NameBuffer.ConnectionIndex = ConnectionIndex
Status& = DeviceIoControl(DeviceHandle&, &H220414, NameBuffer.ConnectionIndex, NameBuffer.Length, NameBuffer.ConnectionIndex, NameBuffer.Length, BytesReturned&, 0)
If Status& = 0 Then ErrorExit ("Could not get TEXT of External Hub Name")
temp$ = "": i = 0
Do While NameBuffer.UnicodeName(i) <> 0: temp$ = temp$ & Chr(NameBuffer.UnicodeName(i)): i = i + 2: Loop
GetExternalHubName$ = temp$
End Function
*********************************************************************************************************
estos son los modulos que tengo para la coneccion quisiera saver si con esto puedo empezar a programar y si nesecito otro o tienes algo mejor que los que tengo para estableser la interfas.
****************____________________________________________________________*****************************
bueno con recpecto a la programacion en el pic cuento con la librerias que me trajo el conpilador y ademas de esto unos cuantos programas que encontre en internet de red_raven en su pagina en dos de el utiliza librerias tanvien para establecer la interfas ademas de esto quisiera saber que tienes tu que me pueda ayudar en esta parte por que es aqui donde la informacion en escasa.
muchas gracias y disculpa la tardansa en responderte....