powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / uart and VB
3 сообщений из 3, страница 1 из 1
uart and VB
    #34142139
vitliy
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Всем доброго времени суток !!!!

Я - начинающий програмист на VB , но вот столкнулся с большой проблемой.
Сделал дипломный проэкт по электронике , который меряет температуру ( это в кратце ) и посылает значения температуры на PC через port1 UART . Все что мне осталось сделать - принять информацию , и по показаниям построить график . Но как это сделать , хоть убейте , не знаю , еще не дошел до уровня обучения работы с файлами . Не знаю , правда , может я вообще говорю глупости , и это задача не выполнима с точки зрения VB , но мне ничего не остается , кроме как обратится к Вам за помощью , так как мой руководитель дипломного проэкта помогать не собирается , все что я от него получил - это програму написаную на Power Basic ( если я не ошибаюсь ) . Он сказал , что если ее немного изменить , то получится то что мне надо , что она делает практически то же самое , но вот Power Basic я знаю еще хуже , точнее не знаю совсем и информации в инете совсем нет .

Воощем , я буду всем признателен , кто откликнется на мою просьбу и поможет хоть чем , может ссылкой на учебный материал , может кто че то поймет в этой программе .....

Зарраннее всем спасибо !!!






#COMPILE EXE "temp2web.exe"
'RESOURCE "UPTIME.PBR"
'********
'* MAIN *
'********
Function PBMAIN()

'display entry text
CONSOLE SCREEN 25,80
STDOUT
Color 10
STDOUT "TEMP2WEB.EXE - get temperature results from COM port & save to WEB"
STDOUT "Copyright (C) Raz Lazar & Ella Vaiserman version 1.0"
Color 7
STDOUT

'**** SETTIG THE DELAY TIME ****
If Command$ = "" Then
delay_time& = 1
Color 11
STDOUT "Note: Default delay of 1 second was chosen for you"
STDOUT
Color 7
Else
delay_time& = Val(Command$)
If 0 < delay_time& And delay_time& < 3600 Then
Color 11
STDOUT "Note: You chose delay time " + Command$
STDOUT
Color 7
Else
Color 12
STDOUT "Error:" + Command$ + " is a bad delay value."
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
End If
'-----------------------------------

'**** SETTING UP COMUNICATION PORT ****
com$ = "COM1"
COMM OPEN com$ AS #1
If ERRCLEAR Then
Color 12
STDOUT "Error: Port " + com$ + " cannot be opened"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "COM1: port opened"
b& = 115200
COMM SET #1 , BAUD = b&
If ERRCLEAR Then
Color 12
STDOUT "Error: baud rate 115200 cannot be set on this host"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "BAUD rate set to 115200"
b& = 8
COMM SET #1 , BYTE = b&
If ERRCLEAR Then
Color 12
STDOUT "Error: number of bits cannot be set to 8 on this host"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "Number of bits set to 8"
s& = 0
COMM SET #1 , PARITYTYPE = s&
If ERRCLEAR Then
Color 12
STDOUT "Error: parity cannot be set to NONE"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "Parity set to NONE"
s& = 0
COMM SET #1 , STOP = s&
If ERRCLEAR Then
Color 12
STDOUT "Error: stop bits cannot be set to 1 bit"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "Stop bits set to 1"
COMM SET #1 , RTSFLOW = 0
If ERRCLEAR Then
Color 12
STDOUT "Error: input hardware flow control can not be set"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "input hardware flow control unset"
COMM SET #1 , CTSFLOW = 0
If ERRCLEAR Then
Color 12
STDOUT "Error: output hardware flow control can not be unset"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "output hardware flow control unset"
COMM SET #1 , XINPFLOW = 1
If ERRCLEAR Then
Color 12
STDOUT "Error: input software flow control can not be set"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "input software flow control SET !"
COMM SET #1 , XOUTFLOW = 0
If ERRCLEAR Then
Color 12
STDOUT "Error: output software flow control can not be unset"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
STDOUT "output software flow control unset"

'------------------------------

'**** CLEANING OLD FILES ****
STDOUT
STDOUT "Cleaning some old files..."
Color 12
Shell Environ$("COMSPEC") + " /C if not exist Thermometer_on_wood.gif echo file 'Thermometer_on_wood.gif' missing !"
Color 7
Shell Environ$("COMSPEC") + " /C if exist top.html attrib -r top.html > NUL: "
Shell Environ$("COMSPEC") + " /C if exist mid.html attrib -r mid.html > NUL: "
Shell Environ$("COMSPEC") + " /C if exist bottom.html attrib -r bottom.html > NUL: "
Shell Environ$("COMSPEC") + " /C if exist temps.csv attrib -r temps.csv > NUL: "
'KILL "top.html"
Shell Environ$("COMSPEC") + " /C if exist top.html del top.html > NUL: "
'KILL "mid.html"
Shell Environ$("COMSPEC") + " /C if exist mid.html del mid.html > NUL: "
'KILL "bottom.html"
Shell Environ$("COMSPEC") + " /C if exist bottom.html del bottom.html > NUL: "
'KILL "temps.csv"
Shell Environ$("COMSPEC") + " /C if exist temps.csv del temps.csv > NUL: "

Open "top.html" For Binary Access Write Lock Write As #2
If ERRCLEAR Then
Color 12
STDOUT "Can not open 'TOP.HTML' file"
Color 7
STDOUT "Press any key..."
WAITKEY$ 'maybe remove
Exit Function 'maybe remove
End If

current_date$ = Date$
current_time$ = Time$

PUT$ #2 ,"<HTML>" + CHR$(13) + CHR$(10)
PUT$ #2 ,"<HEAD>" + CHR$(13) + CHR$(10)
PUT$ #2 ,"<TITLE> Temperature results </TITLE>" + CHR$(13) + CHR$(10)
PUT$ #2 ,"</HEAD>" + CHR$(13) + CHR$(10)
PUT$ #2 , CHR$(13) + CHR$(10)
PUT$ #2 ,"<BODY>" + CHR$(13) + CHR$(10)

PUT$ #2 , "<PRE>"

pic$ = "<IMG SRC=" + CHR$(34) + "Thermometer_on_wood.gif" + CHR$(34) + _
"WIDTH=" + CHR$(34) + "26" + CHR$(34) +_
"HEIGHT=" + CHR$(34) + "86" + CHR$(34) + ">"

PUT$ #2 , "<H2>Temperature results</H2>" + pic$ + CHR$(13) + CHR$(10)
PUT$ #2 , "html file created by 'TEMP2WEB.EXE' © Raz Lazar and Ella Vaiserman <BR><BR>" + CHR$(13) + CHR$(10)
PUT$ #2 , "<HR>" + CHR$(13) + CHR$(10)
PUT$ #2 , "Here are the temperatures results:" + CHR$(13) + CHR$(10)

PUT$ #2 , "<!-- end of top -->" + CHR$(13) + CHR$(10)


Close #2

'-------------------------------------

'**** MAKING BOTTOM OF HTML ****

Open "bottom.html" For Binary Access Write Lock Write As #4
If ERRCLEAR Then
Color 12
STDOUT "Can not open 'BOTTOM.HTML' file"
Color 7
STDOUT "Press any key..."
WAITKEY$ 'maybe remove
Exit Function 'maybe remove
End If

PUT$ #4 , "<!-- begining of bottom -->" + CHR$(13) + CHR$(10)

PUT$ #4 , "<HR>" + CHR$(13) + CHR$(10)
PUT$ #4 , "</PRE>" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT$ #4 ,"</BODY>" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT$ #4 ,"</HTML>" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)

Close #4

'-------------------------------------

'**** LOOP STARTS HERE ****

STDOUT
STDOUT "Loop for collecting temperature readings from logger:"
STDOUT

Do

'sending the g characte to communications port
tx$ = "g"
STDOUT "Sending the 'g' character to logger"
COMM SEND #1 , tx$
If ERRCLEAR Then
Color 12
STDOUT "Error sending g to UART"
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If

'start receiving bytes from Temp Logger
STDOUT "Received bytes..." ;
Color 15
STDOUT "(hit ESC to quit): " ;
Color 7
rx$ = ""
Do
c$ = ""
bytes& = COMM(#1,RXQUE)
If 0 < bytes& Then
COMM RECV #1 ,bytes& , c$
If ERRCLEAR Then
Color 12
STDOUT
STDOUT "Error encountered during transmision."
Color 7
STDOUT "Press any key..."
WAITKEY$
Exit Function
End If
Color 14
STDOUT c$ ;
Color 7
End If
rx$ = rx$ + c$
total_bytes& = Len(rx$)
'maybe the ESC key was hit ?
k$ = INKEY$
LOOP UNTIL 17 < total_bytes& OR k$ = $ESC

'now end the long line
STDOUT
IF k$ = $ESC THEN
EXIT LOOP
End If


current_date$ = Date$
current_time$ = Time$
'STDOUT
'STDOUT "Temp readings: " ;
Color 11
STDOUT current_date$ + " " + current_time$ + " " ;
Color 10

'extract the 8 bytes from transmission
t8$ = Mid$(rx$, 1, 2)
t7$ = Mid$(rx$, 3, 2)
t6$ = Mid$(rx$, 5, 2)
t5$ = Mid$(rx$, 7, 2)
t4$ = Mid$(rx$, 9, 2)
t3$ = Mid$(rx$, 11, 2)
t2$ = Mid$(rx$, 13, 2)
t1$ = Mid$(rx$, 15, 2)

'convert 2 HEX digits of 2C representation to decimal with sign

'** t1 **
c& = Val("&H" + "000000" + t1$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t1$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t1$)
Else
c& = Val("&H" + "000000" + t1$)
End If
t1$ = Format$(c&, "+000;-000")
End If
STDOUT t1$ + " " ;

'** t2 **
c& = Val("&H" + "000000" + t2$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t2$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t2$)
Else
c& = Val("&H" + "000000" + t2$)
End If
t2$ = Format$(c&, "+000;-000")
End If

STDOUT t2$ + " " ;

'** t3 **
c& = Val("&H" + "000000" + t3$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t3$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t3$)
Else
c& = Val("&H" + "000000" + t3$)
End If
t3$ = Format$(c&, "+000;-000")
End If
STDOUT t3$ + " " ;


'** t4 **
c& = Val("&H" + "000000" + t4$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t4$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t4$)
Else
c& = Val("&H" + "000000" + t4$)
End If
t4$ = Format$(c&, "+000;-000")
End If
STDOUT t4$ + " " ;


'** t5 **
c& = Val("&H" + "000000" + t5$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t5$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t5$)
Else
c& = Val("&H" + "000000" + t5$)
End If
t5$ = Format$(c&, "+000;-000")
End If
STDOUT t5$ + " " ;


'** t6 **
c& = Val("&H" + "000000" + t6$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t6$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t6$)
Else
c& = Val("&H" + "000000" + t6$)
End If
t6$ = Format$(c&, "+000;-000")
End If
STDOUT t6$ + " " ;


'** t7 **
c& = Val("&H" + "000000" + t7$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t7$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t7$)
Else
c& = Val("&H" + "000000" + t7$)
End If
t7$ = Format$(c&, "+000;-000")
End If
STDOUT t7$ + " " ;


'** t8 **
c& = Val("&H" + "000000" + t8$)
mask8& = Val("&H80")
'check if error
If c& = mask8& Then
t8$ = "miss"
Else
If (c& And mask8&) = mask8& Then
c& = Val("&H" + "ffffff" + t8$)
Else
c& = Val("&H" + "000000" + t8$)
End If
t8$ = Format$(c&, "+000;-000")
End If
STDOUT t8$ + " "

'******************** end of temp calc ***********************


'**** MAKING MID OF HTML ****
Open "mid.html" For Append As #3
If ERRCLEAR Then
Color 12
STDOUT "Can not open 'MID.HTML' file"
Color 7
STDOUT "Press any key..."
WAITKEY$ 'maybe remove
Exit Function 'maybe remove
End If


'writing temperatures to mid file
Print #3, "<font color=" + Chr$(34) + "#f000ff"; Chr$(34) + ">";
Print #3, current_date$ + " " + current_time$ + " - " + "</font>";
Print #3, "<font color=" + Chr$(34) + "#0000ff"; Chr$(34) + ">";
Print #3, t1$ + " " + t2$ + " " + t3$ + " " + t4$ + " ";
Print #3, t5$ + " " + t6$ + " " + t7$ + " " + t8$ + "</font>"


Close #3

'**** MAKING EXCEL FILE ****
Open "temps.csv" For Append As #5
If ERRCLEAR Then
Color 12
STDOUT "Can not open 'TEMPS.CSV' file"
Color 7
STDOUT "Press any key..."
WAITKEY$ 'maybe remove
Exit Function 'maybe remove
End If


'writing temperatures to temps file
Print #5, current_time$ + ",";
Print #5, t1$ + "," + t2$ + "," + t3$ + "," + t4$ + ",";
Print #5, t5$ + "," + t6$ + "," + t7$ + "," + t8$

Close #5

'**** TIMER ****
t_delay# = delay_time& '1
Color 13
STDOUT "waiting" + Str$(t_delay#) + " sec"
Color 7
t_start# = Timer 'sample initial timer value
Do
t_now# = Timer 'sample current timer value
k$ = INKEY$
LOOP UNTIL (t_delay# < t_now# - t_start#) OR k$ = $ESC
'---------------------

'copy temperatures to index file
Shell Environ$("COMSPEC") + " /C copy top.html + mid.html + bottom.html index.html > NUL: "


'k$ = INKEY$
IF k$ = $ESC THEN
EXIT LOOP
End If

LOOP UNTIL k$ = $ESC

'----------------------------------

STDOUT
STDOUT "Done !"
STDOUT "Press any key..."
WAITKEY$
End Function
...
Рейтинг: 0 / 0
uart and VB
    #34142229
Фотография VladConn
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Я не работал с портами, и для меня это тожэ рэволюционный проэкт. Но если вы сделаете поиск на Yahoo по MSCOMM и uart, то найдете множество интересных ссылок по теме. Коротко - поставьте на форму контроль Microsoft Comm Control, он в VB6 есть (MSCOMM32.OCX), он работает с портами. Поищите на этом форуме по слову MSCOMM. Но скорее всего, скоро откликнутся те, у кого есть код по MSCOMM. Не очень понятно, в чем ваш проэкт меряет температуру (кратце - это что-то вроде фиала или корытца?).

Касательно графа - можно использовать стандартный OLE контроль класса Microsoft Excel Chart или Microsoft Graph Chart. Его совсем просто взять - он сидит прямо на панели и поэтому доступен (сорри за каламбур).

:0)
...
Рейтинг: 0 / 0
uart and VB
    #34142391
Фотография orunbek
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Поищите пример работы с COM-портами на VB в сети, как уже говорил VladConn, таковых должно быть очень много, а прога на PowerBasic особо не сложна. К примеру, вам нужны только эти участки кода,
Например:
Код: plaintext
1.
com$ = "COM1"
COMM OPEN com$ AS # 1 
Здесь он например открывает COM1 порт (а все что до этого вывод рекламы ;)
Код: plaintext
1.
b& =  115200 
COMM SET # 1  , BAUD = b&
дальше установка bits per second
и т.д.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / uart and VB
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]