本文介绍了一种通过DB25并行打印线联接步步高电脑学习机和PC并让学习机的时间自动同步到PC上的电脑时间.这样一启动学习机不需要人为手动设置就可以得到最新时间,仿佛安装了一块电池!
8位的步步高多媒体电脑(软驱1号或者98型学生电脑) 是 8 位的经典 FC 学习机.那最强的地方是可以通过 db25 并口线 (又称打印线缆, 两头都是公的) 访问PC电脑上的文件!所以所有程序都可以放在电脑的硬盘上(或者是任意存储设备,光盘,U盘,软盘都可以), 这样就不用局限于 1.44M 的软盘了.
在电脑上, 你可以运行 pcsvr.exe 来对并行打印口进行侦听.
在步步高 BBGDOS 上 运行 pclink.cmd
联结成功后, 步步高就可以通过这条并行线访问PC上硬盘的数据.显示盘符为C:\> (98型电脑因为有内置2M电子盘,则C:\是电子盘 D:\是PC上的硬盘)
我们都知道,在学习机上, 都没有电池(像PC上主板都会有CMOS电池),断电之后所有的日期和时间都会丢失,重新启动后时间就会被重设,每次都得打 date 和 time 命令很不方便.
因为有 pclink.cmd – pcsvr.exe 我们就可以访问PC上的硬盘数据 我们可以通过运行PC上的一个时间脚本 bat 文件来设置步步高上的时间,具体操作如下:
下面的C/C++程序会根据命令行参数显示设置日期和时间的 dos 命令.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <ctime> #include <string.h> using namespace std; inline void pr(int x) { if (x < 10) { cout << '0'; } cout << x; } int main(int argc, char** argv) { if (argc == 1) { cout << "Create Batch File of Time and Date." << endl; cout << "By http://HelloACM.com" << endl; cout << "Usage: " << argv[0] << " [options] files.bat " << endl; cout << "-t Time; -d Date; -e @Echo off; -s No REM" << endl; return 1; } bool tt = false; bool date = false; bool echo = false; bool rem = true; for (int i = 1; i < argc; i ++) { int len = strlen(argv[i]); for (int j = 0; j < len; j ++) { if (argv[i][j] == 't') { tt = true; } else if (argv[i][j] == 'd') { date = true; } else if (argv[i][j] == 'e') { echo = true; } else if (argv[i][j] == 's') { rem = false; } } } if (echo) { cout << "@echo off" << endl; } if (rem) { cout << "echo TimeDate Batch File For BBG" << endl; cout << "echo Save the Output to File and Run it Remotely on BBG" << endl; cout << "echo BBG-pclink.cmd PC-pcsvr.exe" << endl; cout << "REM Visit http://HelloACM.com" << endl; } time_t now = time(0); tm *ltm = localtime(&now); if (date) { cout << "date "; pr(1 + ltm->tm_mon); cout << "-"; pr(ltm->tm_mday); cout << "-" << 1900 + ltm->tm_year << endl; } if (tt) { cout << "time "; pr(ltm->tm_hour % 12); cout << ":"; pr(ltm->tm_min); cout << ":"; pr(ltm->tm_sec); cout << endl; } return 0; } |
#include <iostream> #include <ctime> #include <string.h> using namespace std; inline void pr(int x) { if (x < 10) { cout << '0'; } cout << x; } int main(int argc, char** argv) { if (argc == 1) { cout << "Create Batch File of Time and Date." << endl; cout << "By http://HelloACM.com" << endl; cout << "Usage: " << argv[0] << " [options] files.bat " << endl; cout << "-t Time; -d Date; -e @Echo off; -s No REM" << endl; return 1; } bool tt = false; bool date = false; bool echo = false; bool rem = true; for (int i = 1; i < argc; i ++) { int len = strlen(argv[i]); for (int j = 0; j < len; j ++) { if (argv[i][j] == 't') { tt = true; } else if (argv[i][j] == 'd') { date = true; } else if (argv[i][j] == 'e') { echo = true; } else if (argv[i][j] == 's') { rem = false; } } } if (echo) { cout << "@echo off" << endl; } if (rem) { cout << "echo TimeDate Batch File For BBG" << endl; cout << "echo Save the Output to File and Run it Remotely on BBG" << endl; cout << "echo BBG-pclink.cmd PC-pcsvr.exe" << endl; cout << "REM Visit http://HelloACM.com" << endl; } time_t now = time(0); tm *ltm = localtime(&now); if (date) { cout << "date "; pr(1 + ltm->tm_mon); cout << "-"; pr(ltm->tm_mday); cout << "-" << 1900 + ltm->tm_year << endl; } if (tt) { cout << "time "; pr(ltm->tm_hour % 12); cout << ":"; pr(ltm->tm_min); cout << ":"; pr(ltm->tm_sec); cout << endl; } return 0; }
在步步高DOS上, date 命令接受的格式是 月-日-年. 格式是固定的,也就是说 月和日是两位数,年是四位数, 如 03-13-2014.
同样, 在步步高DOS上, time 命令接受的格式是 时-分-秒 , 每个数字都是两位数, 比如 00:01:02 ,并且时间是一个0到11的数字, 所以对时间进行除于 12 取余就可以.
在PC上 我们运行 update.bat 批处理, 大概内容是:
@echo off echo Press Ctrl-C to Exit.. echo It will Update Time and Date to UpdateTD.bat every ten seconds. echo On BBG, Run e.g. C:\UpdateTD.bat to Synchronize Time and Date :Update echo Updating Time and Date to UpdateTD.bat .. echo @echo off > UpdateTD.bat echo echo TimeDate Batch File For BBG>> UpdateTD.bat echo echo Save the Output to File and Run it Remotely on BBG>> UpdateTD.bat echo echo BBG-pclink.cmd PC-pcsvr.exe>> UpdateTD.bat echo bbgcdos /z4 >> UpdateTD.bat TimeBat.exe -std >> UpdateTD.bat echo date >> UpdateTD.bat echo time >> UpdateTD.bat echo OK! echo Wait Ten Seconds .. sleep 10000 Goto :Update
这样的话, PC上每隔十秒就会更新一下 updateTD.bat 脚本,当步步高联结上PC后, 运行这个文件就会正确的设置时间和日期.
我们可以通过 sleep.exe (网上很多下载的) 来进行时间延时, 或者可以通过 ping -n 10 127.0.0.1 > NUL 达到类似的效果. ping.exe 命令是用来检查网络是否可以连接 参数是IP地址或者是域名. 参数 -n 10 的意思是测试十次,每次隔一秒,这样就有十秒的延时了. 127.0.0.1 指的是本地IP地址回路, 总是可以连接并存在的. 最后的大于号是用于进行转向,把输出转到 NUL 也就是丢弃不显示.
被PC上更新的 UpdateTD.bat 内容大概是:
@echo off echo TimeDate Batch File For BBG echo Save the Output to File and Run it Remotely on BBG echo BBG-pclink.cmd PC-pcsvr.exe bbgcdos /z4 date 03-13-2014 time 06:31:12 date time
这样可以在 步步高的 autoexec.bat 里 添加运行这个脚本
@echo off pclink.cmd C:\UpdateTD.bat
UpdateTD.bat 的路径根据实际情况不同可以进行修改.
zip程序包可以在 这里下载 (170kb) .
这样, 不需要电池,每次启动步步高,你就会有最新的日期和时间了!
loading...
上一篇: 步步高学生电脑上 Basic 编程语言 peek 用法示例
下一篇: 在步步高多媒体学生电脑 - 软驱 1 号上用BASIC语言的PEEK命令