3 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3Aplicacao 3 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3Uso 3 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3Analista Resp.3 Data 3 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 3 / / 3 33 3 / / 3 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU*/User Function BalRodovPrivate cPesoAt := Space(30)Private cPesStr := Space(30) Private cCfg :="COM1:4800,n,8,1"Private nH := 0SetPrvt("oDlg1","oSay1","oSay2","oPesStr","oPeso","oSBtn1")oDlg1 := MSDialog():New( 091,232,304,578,"Balanca rodoviaria",,,.F.,,,,,,.T.,,,.T. )oSay1 := TSay():New( 028,016,{||"STRING DA COM1"},oDlg1,,,.F.,.F.,.F.,.T.,CLR_BLACK,CLR_WHITE,060,008)oSay2 := TSay():New( 045,017,{||"PESO TRATADO"},oDlg1,,,.F.,.F.,.F.,.T.,CLR_BLACK,CLR_WHITE,059,008)oPesStr := TGet():New( 028,088,{|u| If(PCount()>0,cPesStr:=u,cPesStr)},oDlg1,060,008,'',,CLR_BLACK,CLR_WHITE,,,,.T.,"",,,.F.,.F.,,.F.,.F.,"","cPesStr",,)oPeso := TGet():New( 048,088,{|u| If(PCount()>0,cPesoAt:=u,cPesoAt)},oDlg1,060,008,'',,CLR_BLACK,CLR_WHITE,,,,.T.,"",,,.F.,.F.,,.F.,.F.,"","cPesoAt",,)oSBtn1 := SButton():New( 072,120,1,{|| LerPeso()},oDlg1,,"", )oDlg1:Activate(,,,.T.)Return/*/UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3 Programa 3 LerPeso 3 Autor 3 LUIS LACOMBE 3 Data 3 18/04/13 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3Descri...o 3Faz a requisicao de peso para a balanca e le o retorno. 33 3Para funcionar, eh importante verificar o protocolo de 33 3comunicacao da balanca. No caso da TOLEDO,ela tem que estar 33 3usando o protocolo que responda ao sinal ENQ, por exemplo 33 3o protocolo P05 ou P05A. Importante lembrar que a funcao 33 3nao trata a estabilizacao de peso. Se quiser receber o peso 33 3somente quando ele estabilizar,use o protocolo adequado como33 3P05 da TOLEDO. 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU/*/Static Function LerPeso()Local cPeso := 0Local cBuffercCfg :="COM1:4800,n,8,1"lRet := msOpenPort(nH,cCfg)if(!lRet) Alert("Falha ao conectar com a porta serial") ReturnEndIf//msWrite(nH,Chr(5))//Sleep(200)For ncont := 1 To 50 msRead(nH,@cBuffer) if(!Empty(cBuffer)) // ALERT(cBuffer) cPesStr := cBuffer cPeso := IsNumber(cBuffer) Exit EndIfNextmsClosePort(nH) cPesoAt := cPeso// PRA TESTAR O PROGRAMA SEM BALANCA//nPeso := Val(cSimPes)Return/*/UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3 Programa 3 IsNumber 3 Autor 3 LUIS LACOMBE 3 Data 3 18/04/13 3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3Descri...o 3Separa os caracteres numericos da string recebida da balanca3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU/*/Static Function IsNumber(cNum)Local nPosPar Local cPesB := ""Local cNumeros := "0123456789." Local cNewNum := ""Local nPes := 0//bloco que separa o numero da string enviada pela balancaFor nCont := 1 To Len(cNum) if(SubStr(cNum,nCont,1)=="E") Exit EndIf if(SubStr(cNum,nCont,1)=="I") // peso instavel Return "-1" EndIf if(SubStr(cNum,nCont,1)$cNumeros) cNewNum += SubStr(cNum,nCont,1) EndIfNext nContcPesB := cNewNumReturn cPesB