first serial com test
This commit is contained in:
parent
2c30301744
commit
e492618b06
1 changed files with 10 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import SerialPort from 'serialport';
|
||||||
|
|
||||||
export default class Login extends Component {
|
export default class Login extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -24,11 +25,17 @@ export default class Login extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const port = new SerialPort('COM3');
|
||||||
|
const triggerOn = () => {
|
||||||
|
port.write('on');
|
||||||
|
};
|
||||||
|
const triggerOff = () => {
|
||||||
|
port.write('off');
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Login</h2>
|
<button onClick={triggerOn}>ON</button>
|
||||||
<input onChange={this.handleChange} type="text" value={this.state.username} />
|
<button onClick={triggerOff}>OFF</button>
|
||||||
<button onClick={this.handleLogin}>Log In</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue