• COM port communication

    From Claudio H@21:1/5 to All on Mon Apr 12 11:06:20 2021
    Hi

    Which functions are you using to read and send data through an rs232 connection?

    I've been using CT's COM_xxxxx but lately after installing certain windows 10 updates, the program closes with no messages.

    If in the program shortcut in the Compatibility tag I check "Run this program in compatibility mode for" and select Windows 7 the program runs flawlessly.

    Regards
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Claudio H on Tue Apr 13 06:51:15 2021
    On Monday, April 12, 2021 at 11:06:21 AM UTC-7, Claudio H wrote:

    Which functions are you using to read and send data through
    an rs232 connection?

    I don't. Just a disclaimer...

    I've been using CT's COM_xxxxx but lately after installing
    certain windows 10 updates, the program closes with no
    messages.

    https://techcommunity.microsoft.com/t5/microsoft-usb-blog/what-is-new-with-serial-in-windows-10/ba-p/270855

    "Provide a Windows Runtime API for communication with Serial devices." https://docs.microsoft.com/en-us/uwp/api/Windows.Devices.SerialCommunication?redirectedfrom=MSDN&view=winrt-19041
    ... and it appears the RS-232 device has to be "properly" installed.

    If in the program shortcut in the Compatibility tag I check
    "Run this program in compatibility mode for" and select
    Windows 7 the program runs flawlessly.

    I'm afraid it is going to be some work to "wrap" this. Might be easier to upgrade the communication hardware, and use their proprietary interface?

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Tue Apr 13 07:37:43 2021
    Hi David

    Thanks for your answer but both articles are a couple of years old and this issue started now, so far verified with versions 2004 and 20H2

    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ariel Paredes@21:1/5 to All on Tue Apr 13 08:26:13 2021
    El lunes, 12 de abril de 2021 a las 13:06:21 UTC-5, Claudio H escribió:
    Hi

    Which functions are you using to read and send data through an rs232 connection?

    I've been using CT's COM_xxxxx but lately after installing certain windows 10 updates, the program closes with no messages.

    If in the program shortcut in the Compatibility tag I check "Run this program in compatibility mode for" and select Windows 7 the program runs flawlessly.

    Regards
    Claudio H

    hi, Try

    read scale serial Com and usb in Windows 10 64 bits Pro
    with 3 decimals


    nCant := BASCMAG(1) //Port 1,2,3,etc

    *--------------------------------------------
    Function BASCMAG( Arg1 )

    Local Local1, Local2, Local3
    Set decimals to 3
    Local1 := 0
    Local2 := 0

    com_open(Arg1, 100)
    com_init(Arg1, 9600, "N", 8, 1) // configuracion de bascula
    com_flush(Arg1)
    com_send(Arg1, "P") // Bascula marca torrey

    Do while com_count(Arg1) < 1 .AND. Local2 < 6
    millisec(1)
    Local2++
    Enddo
    Local3 := com_read(Arg1,100)


    If ( Len(Local3) >= 6 )
    Local1 := Val(SubStr(Local3, 1, 8))
    com_close(Arg1)
    Set decimals to 2
    Return Local1
    Else
    com_close(Arg1)
    Return Local1
    Endif

    regards

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Tue Apr 13 08:32:58 2021
    Ariel

    Estas trabajando con xHB comercial o free?
    En caso del comercial, estas usando xHBcomm.lib o xHBCommDLL.lib?
    En caso del free que lib estas usando?

    Saludos
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MOL@21:1/5 to All on Tue Apr 13 10:08:05 2021
    wtorek, 13 kwietnia 2021 o 17:32:59 UTC+2 Claudio H napisał(a):
    Ariel

    Estas trabajando con xHB comercial o free?
    En caso del comercial, estas usando xHBcomm.lib o xHBCommDLL.lib?
    En caso del free que lib estas usando?

    Saludos
    Claudio H

    Hi!
    I'm using Harbour. Maybe it will work with xHarbour.
    Here is piece of my code for communication with registering cashes:

    #include "hbsocket.ch"
    #include "hbclass.ch"

    #define ECR_TIMEOUT 3000 // 3 seconds

    #define ECR_PobranieDanych "0"
    #define ECR_WyslanieDanych "1"
    #define ECR_PobranieZerowanieDanych "2"

    declare window OknoStatusTransmisji
    declare window OknoProgramowanieKasy
    declare window OknoOdbiorSprzedazy

    CLASS KF_KOMUNIKATOR
    DATA lTcpIP INIT .F.
    DATA oPort INIT NIL
    //
    DATA cIpAdress INIT ""
    DATA nIpPort INIT 0
    DATA nTimeOut INIT 5000 // 3 sekundy
    // dalej obsługa przez serial
    DATA cKFPortName INIT "" // nazwa portu COM
    DATA nPredkosc INIT 9600
    DATA nParzystosc INIT NOPARITY
    DATA nBitow INIT 8
    DATA nBitowStopu INIT ONESTOPBIT
    // stan portu
    DATA Open INIT .F.

    METHOD INIT SETGET
    METHOD WRITE SETGET
    METHOD READ SETGET
    METHOD CLOSE SETGET
    ENDCLASS

    *---------
    METHOD Init(lTcpIp, cNazwaPortu, nPort, nPredkosc, nParzystosc, nBitow, nBitowStopu, nTimeout) CLASS KF_KOMUNIKATOR

    ::lTcpIp := lTcpIp

    if ::lTcpIp
    if HB_PING(cNazwaPortu)<>0
    MsgStop("Kasa fiskalna nie odpowiada na adresie: "+cNazwaPortu)
    return NIL
    endif

    if Empty( ::oPort := hb_socketOpen( HB_SOCKET_AF_INET, HB_SOCKET_PT_STREAM)) //, HB_SOCKET_IPPROTO_UDP ) )
    //MsgStop( "socket create error " + hb_ntos( hb_socketGetError() ) )
    MsgStop( "Błąd przy zestawieniu połączenia", "Komunikacja z kasą fiskalną")
    return NIL
    endif

    if ! hb_socketConnect( ::oPort, { HB_SOCKET_AF_INET, cNazwaPortu, nPort } )
    //MsgStop( "socket connect error " + hb_ntos( hb_socketGetError() ) )
    MsgStop( "Błąd przy zestawieniu połączenia (socket connect error #"+ hb_ntos( hb_socketGetError() )+")", "Komunikacja z kasą fiskalną")
    return NIL
    endif
    ::cIpAdress := cNazwaPortu
    ::nIpPort := nPort
    ::Open := .t.

    else

    ::cKFPortName := cNazwaPortu
    ::nPredkosc := nPredkosc
    ::nParzystosc := nParzystosc
    ::nBitow := nBitow
    ::nBitowStopu := nBitowStopu

    ::oPort := win_com():Init(cNazwaPortu, nPredkosc, nParzystosc, nBitow, nBitowStopu)
    if !::oPort:Open
    MsgBox("Błąd otwarcia portu komunikacyjnego - BRAK POŁĄCZENIA Z KASĄ FISKALNĄ!", "Komunikacja z kasą fiskalną" )
    ::oPort := NIL
    return NIL
    else
    // Otwarto z powodzeniem
    DoRejestruTransmisji("Otwarto port komunikacyjny "+cPortName)
    ::oPort:QueueSize( 1000, 1000 )
    ::oPort:Purge()
    //TimeOuts( nInterval, nReadMultiplier, nReadConstant, nWriteMultiplier, nWriteConstant )
    ::oPort:Timeouts(1500,1000,20000,1000,20000)

    ::oPort:RTSFlow(.t.)
    ::oPort:DTRFlow(.t.)
    ::oPort:XonXoffFlow(.t.)
    ::oPort:SetDTR(.t.)
    ::oPort:SetDTR(.t.)
    ::oPort:SetRTS(.t.)

    endif
    endif

    ::nTimeOut := nTimeout
    ::Open := .t.
    return SELF
    *---------
    METHOD Write(cDaneDoWyslania) CLASS KF_KOMUNIKATOR
    local nWyslano := 0

    if ::lTcpIp
    hb_socketSend( ::oPort, cDaneDoWyslania )
    nWyslano := len(cDaneDoWyslania)
    else
    nWyslano := ::oPort:Write(cDaneDoWyslania)
    //if !(nWyslano == len(cDaneDoWyslania))
    // MsgStop("Operacja zakończona niepowodzeniem", "WYDRUK FISKALNY" )
    // return .f.
    //endif
    endif
    return nWyslano
    *---------
    METHOD Read(cOdpowiedz, n) CLASS KF_KOMUNIKATOR
    hb_default(@n,1)
    cOdpowiedz := space(n)
    if ::lTcpIp
    n := hb_socketRecv( ::oPort, @cOdpowiedz,,, ::nTimeOut )
    else
    ::oPort:Read(@cOdpowiedz, n)
    endif
    return cOdpowiedz
    *---------
    METHOD Close CLASS KF_KOMUNIKATOR
    local nCount := 0
    local cOdpowiedz := ""

    if ::lTcpIp
    hb_socketShutdown( ::oPort )
    hb_socketClose( ::oPort )
    else
    ::oPort:QueueStatus( , , , , , @nCount, )
    ::oPort:Read(@cOdpowiedz, nCount)
    ::oPort:Purge()
    ::oPort:RTSFlow(.f.)
    ::oPort:DTRFlow(.f.)
    ::oPort:XonXoffFlow(.f.)
    ::oPort:SetDTR(.f.)
    ::oPort:SetDTR(.f.)
    ::oPort:SetRTS(.f.)
    ::oPort:Close()
    endif
    DoRejestruTransmisji("Zamknięto port komunikacyjny")
    ::oPort := NIL
    return
    *---------
    METHOD Purge CLASS KF_KOMUNIKATOR
    if ::lTcpIp
    else
    ::oPort:Purge()
    endif
    return

    *-------------------------

    FUNCTION ECR_InitTango
    param nNumerKasy, lTcpIp, cPortName, nPredkosc, cAdresTcpIp, nPortTcpIp

    local lRet := .t., cOdpowiedz := space(1000)
    local nNumerKasyPodlaczonej

    ECR_LastErrorNR := 0
    ECR_LastErrorTXT := ""

    if type("nNumerKasy") <>"N"
    nNumerKasy := val(nNumerKasy)
    endif

    if type("cPortName") == "N"
    cPortName := "COM"+alltrim(str(cPortName))
    endif

    oWinPort := KF_Komunikator():Init(lTcpIp,;
    if(lTcpIp,cAdresTcpIp,cPortName),;
    nPortTcpIp,;
    nPredkosc,;
    NOPARITY, 8, ONESTOPBIT,;
    ECR_TIMEOUT)

    if oWinPort = NIL
    lRet := .f.
    //walert("Błąd otwarcia portu komunikacyjnego",,"" )
    MsgStop("Błąd otwarcia portu komunikacyjnego "+if(lTcpIP, cPortName+":"+hb_ntos(nPredkosc),cAdresTcpIp+":"+hb_ntos(nPortTcpIp)),,"" )
    DoRejestruTransmisji("Błąd otwarcia portu komunikacyjnego "+if(lTcpIP, cPortName+":"+hb_ntos(nPredkosc),cAdresTcpIp+":"+hb_ntos(nPortTcpIp)), )
    SetProperty(ThisWindow.Name,"T_TypOperacji","Value","Błąd otwarcia portu komunikacyjnego "+if(lTcpIP, cPortName+":"+hb_ntos(nPredkosc),cAdresTcpIp+":"+hb_ntos(nPortTcpIp)))
    SetProperty(ThisWindow.Name,"T_TypOperacji","FontColor", {255,0,0} )
    return lRet
    endif

    // sprawdź numer kasy
    nNumerKasyPodlaczonej := ECR_OdczytajNumerKasy()
    if nNumerKasyPodlaczonej < 0
    ECR_COMClose()
    lRet := .f.
    else

    if nNumerKasy <> nNumerKasyPodlaczonej .and. nNumerKasy > 0
    cTXTError := "Próba połączenia z kasą o innym numerze"
    WAlert("Próba połączenia z kasą o innym numerze!")
    DoRejestruTransmisji("Próba połączenia z kasą o innym numerze!")
    SetProperty(ThisWindow.Name,"T_TypOperacji","Value", "Próba połączenia z kasą o innym numerze!")
    SetProperty(ThisWindow.Name,"T_TypOperacji","FontColor", {255,0,0} )

    ECR_COMClose()
    lRet := .f.
    else
    DoRejestruTransmisji("Połączono z kasą #"+alltrim(str(nNumerKasyPodlaczonej)))
    //oWinPort:Purge()
    endif
    endif
    RETURN lRet
    *-------------------
    function ECR_ComClose
    if oWinPort <> NIL
    oWinPort:Close()
    endif
    oWinPort := NIL
    return .t.
    *-------------------

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Claudio H on Tue Apr 13 10:37:45 2021
    Dear Claudio H:

    On Tuesday, April 13, 2021 at 7:37:44 AM UTC-7, Claudio H wrote:

    Thanks for your answer but both articles are a couple of years
    old and this issue started now, so far verified with versions
    2004 and 20H2

    OK, so you've never known Micro$haft to deprecate a feature, still allow you to use it for some period of time, and then shut the door?

    You have other answers, and mine is more along the lines of "here is how Micro$haft wants you to do it", and provides no code to try. So I'll assume we don't need to discuss this further. Sooner or later we will need to adopt the M$ API here, if under
    the Clipper tools aegis.

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ariel Paredes@21:1/5 to All on Tue Apr 13 17:15:04 2021
    El martes, 13 de abril de 2021 a las 10:32:59 UTC-5, Claudio H escribió:
    Ariel

    Estas trabajando con xHB comercial o free?
    En caso del comercial, estas usando xHBcomm.lib o xHBCommDLL.lib?
    En caso del free que lib estas usando?

    Saludos
    Claudio H


    Hola Claudio H, estoy usando xharbour comercial
    utilizo la lib CT3Comm.lib

    Saludos!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Wed Apr 14 09:05:42 2021
    Hola Ariel
    Tenes algun documento o referencia de CT3Comm.lib?
    Gracias
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Thu Apr 15 08:47:16 2021
    After some tests we have determined that the problem only shows with commercial xHBComm.lib (Luiz?)

    Migrating to CT3Comm.lib the application works ok in all those win10 builds where it was crashing.

    Regards
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)